storing values in matrix using for loop

3 次查看(过去 30 天)
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)]

采纳的回答

KSSV
KSSV 2019-3-13
编辑:KSSV 2019-3-13
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]

更多回答(0 个)

类别

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