transform an empty matrix '0x0 double' into a matrix '0x1 uint8'
11 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Alberto Acri
el 20 de Jul. de 2023
Comentada: Walter Roberson
el 20 de Jul. de 2023
Hello! How can I transform an empty matrix '0x0 double' into a matrix '0x1 uint8' as in the figure?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1438858/image.png)
For example in my case, I have a cell 'test_p'. Rows 3 and 4 (0x0 double) should become like rows 1,2 and 5 (0x1 uint8).
test_p = importdata("test_p.mat");
M_0x1_uint8 = test_p{1, 1};
M_0x0_double = test_p{3, 1};
The uint8 command should do the trick. How can I apply it only to those '0x0 double' arrays ?
0 comentarios
Respuesta aceptada
Walter Roberson
el 20 de Jul. de 2023
mask = cellfun(@isempty, test_p);
test_p(mask) = {zeros(0,1,'uin8')};
Unless, that is, you might have entries that are (for example) '' (the empty character vector). In such a case
mask = cellfun(@(C) isdouble(C) && isempty(C), test_p);
test_p(mask) = {zeros(0,1,'uin8')};
2 comentarios
Walter Roberson
el 20 de Jul. de 2023
The first version of the code looks inside the cell array test_p and finds all of the entries that are "empty" and changes them all to 0 x 1 uint8.
The second version of the code looks inside the cell array test_p and finds all of the double precision entries that are "empty" and changes them all to 0 x 1 uint8.
The difference is that hypothetically your cell array might contain empty entries that are not double precision and that you might not want converted. For example it might contain empty character vectors or empty figure() handles that you want to leave alone.
There is another possibility that this code does not account for in the form posted: you might potentially have some double precision empty arrays that are not 0 x 0 that you do not want converted. For example you could theoretically have an 768 x 1024 x 3 x 0 array that you did not want converted.
Más respuestas (1)
Ver también
Categorías
Más información sobre Cell Arrays en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!