How do I obtain accurate result for this code snippet

조회 수: 2 (최근 30일)
Hayatullahi Adeyemo
Hayatullahi Adeyemo 2017년 11월 14일
답변: mounika 2017년 11월 14일
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]

답변 (1개)

mounika
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);
for your reference, you can look at the num2cell documentation too.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by