How do I obtain accurate result for this code snippet
1 次查看(过去 30 天)
显示 更早的评论
I have a code segment like this below:
clc;
n=5;
vv=cell(1,n);
for i=1:n
vv{n}=squ(i);
end
disp(vv);
I want to have output as: [1] [4] [9] [16] [25]. Please how do I do it because I kept on getting output as [] [] [] [] [25]
0 个评论
回答(1 个)
mounika
2017-11-14
If just creating output as a cell array is the interest, you can try the following:
squ = [1,4,9,16,25];
x = num2cell(squ);
disp(x);
0 个评论
另请参阅
类别
在 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!