Data with names through a loop in vector?
1 次查看(过去 30 天)
显示 更早的评论
Hello
I try to explain my problem with a simple code. Assuming I have dataset given as below:
z0=0; z1=500; z2=233; z3=677; z4=88; z5=8888; z6=22;
For further calculations, I would like to have all single data in one vector. I can easy write it like this:
z=[z1,z2,z3,z4,z5,z6];
For 6 numbers is this not a problem, but what if I got a set of 1000 such data?
Therefore, I would like to have a loop which creates such a vector automatically. Does anybody have an idea?
Tanks for your hints.
2 个评论
采纳的回答
Azzi Abdelmalek
2012-11-2
If your data are saved in a mat file
data=load('yourfile')
for k=1:1000
out(k)=data.(sprintf('z%d',k))
end
3 个评论
更多回答(1 个)
Matt Fig
2012-11-2
Did you create this data? It is best to start over and not create such a mess in the first place..... If possible, I would go back and get the data into a proper form, such as a cell array or structure. Then further manipulations will be easier.
3 个评论
Matt Fig
2012-11-2
That's o.k. What form is the data in? Is it in a .mat file? If so, see Azzi's suggestion. If not, tell us how the data is stored and we will make further suggestions.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Whos 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!