storing values in matrix using for loop
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Darpan Verma
am 13 Mär. 2019
Kommentiert: madhan ravi
am 13 Mär. 2019
Hi I want to store values in a [3x3] matrix but getting error. Any help would be appreciated
for i=1:3
answerA(i,1)=1*i
answerB(i,2)=2*i
answerC(i,3)=i
% tableA=[answerA answerB answer C]
end
table=[reshape(answerA,[],1) reshape(answerB,[],1) reshape(answerC,[],1)]
% table=[reshape(answerA,[],1)]
ERROR:
Error using horzcat
Dimensions of arrays being concatenated are not consistent.
Error in AllCurvesfit (line 80)
table=[reshape(answerA,[],1) reshape(answerB,[],1)]
0 Kommentare
Akzeptierte Antwort
KSSV
am 13 Mär. 2019
Bearbeitet: KSSV
am 13 Mär. 2019
answerA = zeros(3,1) ;
answerB = zeros(3,1) ;
answerC = zeros(3,1) ;
for i=1:3
answerA(i)=1*i ;
answerB(i)=2*i ;
answerC(i)=i ;
end
table=[answerA answerB answerC]
May be you wanted:
T = table(answerA, answerB, answerC)
The above can be achieved without loops also:
i = (1:3)' ;
A = [i 2*i i]
1 Kommentar
Weitere Antworten (0)
Siehe auch
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!