How can i access the values in a cell array and assign multiple values from column of the cell to a variable using a for loop?
2 次查看(过去 30 天)
显示 更早的评论
Hi. I have a cell 30x1 and each cell has 4 columns and 1 row. I want to assign the row values from 4 columns to 4 variables using a for loop. I tried using
for i = range(1:30)
for j = range(1:4)
Y = P{i,1}(1,j);
A = P{i,1}(1,2);
B = P{i,1}(1,3);
C = P{i,1}(1,4);
end
end
but I only assigned the last value form the last cell to the variable. Can someone help me where am i making an error?
0 个评论
回答(1 个)
Image Analyst
2018-10-10
Y, A, B, and C get overwritten on every single iteration.
Why not simply use cell2mat(P)?
2 个评论
Image Analyst
2018-10-10
How are you combining a bunch of numbers into a single number? Summing them? Taking their mean? Please give a small example.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!