Storing value outside the loop using reshape function
1 次查看(过去 30 天)
显示 更早的评论
Hello everyone!
I was working on some code and I can't silly I'm doing. Here I have attached my problem in short format. I know its still quite lengthy but please help me out. After hours I'm unable to figure out what I'm doing wrong.
l=[4; 2.8];
[mL,nL]=size(l);
A=[15.0 22.5 30.0 37.5 45.0 52.5 60.0 ]';
for h=1:2
L=l(h);
X=[L*100/16 L*100/10];
XD = A(A>=X(1,1) & A<= X(1,2));
[mX,nX]=size(XD);
index = 0;
for i=1:mX
index=index+1;
LL(index)=l(h);
XDD(index)=XD(i);
end
A1 = [reshape(LL,[],1)];
A2 = [reshape(XDD,[],1)];
L=[A1 A2]
end
Running the above code gives following output:
L = 4 30
4 37.5
L = 2.8 22.5
4 37.5
Desired Output
L = 4 30
4 37.5
L = 2.8 22.5
0 个评论
采纳的回答
Stéphane Vaillant
2021-4-12
t seems the variables LL and XDD are uninitialized and so keep their value on the second iteration of the loop. What happens when adding LL=[]; XDD=[]; just under "for h=1:2" ?
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Whos 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!