Singleton error causing mismatch?

What is going on here?
Assignment has more non-singleton rhs dimensions than non-singleton
subscripts
Error in Reduced_DLF_finder (line 18)
report(i,1)=props(i).name;
The props piece comes out with a single string, like 'hello', when I type it in the Matlab window. Just trying to put it into a slot in a report table I'm building.
What am I doing wrong?

Respuestas (1)

per isakson
per isakson el 24 de Jun. de 2018
Editada: per isakson el 24 de Jun. de 2018
Try replacing
report(i,1)=props(i).name;
by
report(i,1)={props(i).name};
and see table, Table array with named variables that can contain different types together with its references See also:.

7 comentarios

David Pesetsky
David Pesetsky el 24 de Jun. de 2018
Editada: David Pesetsky el 24 de Jun. de 2018
Now I get
Conversion to double from cell is not possible.
The other columns of report are numerical.
Now you report a new problem.
I assume that
report(i,1)={props(i).name};
did work.
I cannot guess how you tried to assign "numerical".
This is an example from the documentation and my assignment of 99 to Var1
>> T = table({'M';'M';'F';'F';'F'},[38;43;38;40;49], ...
[71;69;64;67;64],[176;163;131;133;119])
T =
5×4 table
Var1 Var2 Var3 Var4
____ ____ ____ ____
'M' 38 71 176
'M' 43 69 163
'F' 38 64 131
'F' 40 67 133
'F' 49 64 119
>> T{1,2} = 99
T =
5×4 table
Var1 Var2 Var3 Var4
____ ____ ____ ____
'M' 99 71 176
'M' 43 69 163
'F' 38 64 131
'F' 40 67 133
'F' 49 64 119
To learn Matlab you need to read the documentation.
In fact that did work. It's when I try to load other variables into the Report columns, that I get that new error. The new variables are just values. The 1st line is a cell array:
report(i,1)={props(i).name};
report(i,2)=reduced_DLF(i).max(1,2);
report(i,3)=reduced_DLF(i).max(1,1);
hhh
Study Access Data in a Table carefully.
Note in my example
>> T{1,2} = 99
with curly braces
David Pesetsky
David Pesetsky el 25 de Jun. de 2018
Editada: per isakson el 25 de Jun. de 2018
So, I was able to load up "report" with all the elements that I care about.. turns out some of the elements were "emprty", so were messing up the assigning:
for i = 1:num_of_mat
% report{i,1}={reduced_DLF(i).name};
if ~isempty(reduced_DLF(i).max)
report{kkk,1}={reduced_DLF(i).name};
report{kkk,2}=reduced_DLF(i).max(1,2);
report{kkk,3}=reduced_DLF(i).max(1,1);
kkk=kkk+1;
end
end
% csvwrite('report.txt',report)
% xlswrite('report.xls',report);
But now, "report" is a cell array having the 1st column as "strings", and the rest as numbers. I just need to write out "report". csvwrite chokes on the mixture of cell types? And xlswrite ignores the 1st column of strings and just writes the numeric cells.
per isakson
per isakson el 25 de Jun. de 2018
Editada: per isakson el 25 de Jun. de 2018
"But now, "report" is a cell array" I though report was a Matlab table, which should be obvious from my answer and comments. I might have been mistaken. However, you didn't put me straight. Now you say that report is a cell array.
"csvwrite chokes on the mixture of cell types" That is an expected behaviour. (It's easier to write a table to a file.) See the text under the Examples tab of tprintf, tprintf writes tabular data to a text file on printing cell arrays to text files.
David Pesetsky
David Pesetsky el 26 de Jun. de 2018
Is these any simpler way to export the cell array to txt or xls?

Iniciar sesión para comentar.

Categorías

Más información sobre Characters and Strings en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 24 de Jun. de 2018

Comentada:

el 26 de Jun. de 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by