Run a vectorelement in a for loop
정보
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
이전 댓글 표시
Hi!
I have a vector x=[x(2),x(3),x(4),....,x(9)]. Now I want to change/run each element in a for loop. I did:
if true
x(2)=0.05:0.01:0.15;
x(3)=0.10:0.01:0.30;
x(4)=0.15:0.01:0.50;
x(5)=0.05:0.01:0.10;
x(6)=0.05:0.01:0.15;
x(7)=0.10:0.02:0.30;
x(8)=0.15:0.02:0.30;
x(9)=0.10:0.02:0.30;
N=length(x(2))*length(x(3))*length(x(4))*length(x(5))*length(x(6))*length(x(7))*length(x(8))*length(x(9));
%%---------------------Thickness variation------------------------- %%
numorder=0;
for ii=1:length(x(2))
for jj=1:length(x(3))
for kk=1:length(x(4))
for ll=1:length(x(5))
for mm=1:length(x(6))
for nn=1:length(x(7))
for oo=1:length(x(8))
for pp=1:length(x(9))
numorder=numorder+1;
run a function
end
Unfortunately the error is a common one, bur I dont understand the explanation. The Error is: In an assignment A(I) = B, the number of elements in B and I must be the same. I understand that I have to change the form of my code, but how it should be?
Thanks!
댓글 수: 1
Michael Haderlein
2015년 2월 5일
Huh, what are you going to do? The error comes from the lines where you write
x(.)=...
The right hand side is an array with, say, 10 elements while the left hand side is only one scalar. That doesn't match. Please tell us what's the purpose of the script, then we can help you. Btw, if you really want to vary the first element from 0.05 to 0.15 with 0.01 increments, the second one similarly and so on, you'll get about 500'000'000 values - are you sure you want that? That's also how often the function (run a function) will be executed. It could take quite some while...
답변 (0개)
이 질문은 마감되었습니다.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!