How to store a string data into an array
Mostrar comentarios más antiguos
I have a an array like this:
trainLabels = zeros(315,1);
And I would like to put a string for example 'bass' on every element of that array. I tried using
fold = 'bass';
testLabels(testctr,1) = fold;
but its giving me this error:
Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 1-by-4.
Respuestas (1)
madhan ravi
el 9 de Dic. de 2018
trainLabels = cell(315,1);
trainLabels(:)={'bass'}
15 comentarios
Janrex Pensader
el 9 de Dic. de 2018
madhan ravi
el 9 de Dic. de 2018
ah then it would be
trainLabels{i} = {your variable} % i is the loop iterator
Janrex Pensader
el 9 de Dic. de 2018
madhan ravi
el 9 de Dic. de 2018
Ah upload your datas as a .mat file and upload the part of the code your trying to store datas
Janrex Pensader
el 9 de Dic. de 2018
madhan ravi
el 9 de Dic. de 2018
You didn't look into my answer properly! You forgot to add this line before the loop
trainLabels = cell(315,1);
Janrex Pensader
el 9 de Dic. de 2018
Janrex Pensader
el 9 de Dic. de 2018
madhan ravi
el 9 de Dic. de 2018
madhan ravi
el 9 de Dic. de 2018
celldisp(testLabels) %to view the contents of the cell
If my answered solved your question make sure to accept the answer and give a vote.
Janrex Pensader
el 9 de Dic. de 2018
madhan ravi
el 9 de Dic. de 2018
Editada: madhan ravi
el 9 de Dic. de 2018
"I'm going to connect this to a code that needs an ordinary array of names."
why not ? you can easily connect it
Janrex Pensader
el 9 de Dic. de 2018
madhan ravi
el 9 de Dic. de 2018
To be frank and honest I don't have any experience with that field but in the link you suggested cell arrays ahd been used , why not try it and find it out?
Janrex Pensader
el 9 de Dic. de 2018
Categorías
Más información sobre File Operations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!