How can I put data into a Cell

2 Ansichten (letzte 30 Tage)
Anne
Anne am 23 Mär. 2017
Kommentiert: dpb am 25 Mär. 2017
I have a cell Name = {} And i need to make a list of names using a loop. How do I do this without overwriting ? Thanks

Antworten (2)

Adam
Adam am 23 Mär. 2017
Bearbeitet: Adam am 23 Mär. 2017
for n = 1:numNames
Name{n} = getYourNameFromSomewhere( n );
end
Doing it in a loop implies your names are somewhere where you can assign them without needing to hard code them. Whether that is the case or not I don't know so the above is kind of pseudo-code
  3 Kommentare
dpb
dpb am 25 Mär. 2017
[ Anne's Answer moved to comment as is followup ?-- dpb]
thank You. But i get a lot of [] [] [] []
dpb
dpb am 25 Mär. 2017
"Show your work!" We can't debug what we can't see...need the code you used and a sample of the data you tried to assign.

Melden Sie sich an, um zu kommentieren.


Anne
Anne am 23 Mär. 2017
thank You. But i get a lot of [] [] [] []
  1 Kommentar
Adam
Adam am 23 Mär. 2017
Well, it depends entirely on how you get hold of all your names in a loop. Using Jan's code to initialise the array that is what you will start with. If your code in the for loop fails to assign anything then you will end up with that still too.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by