How do I fix this error: In an assignment A(I) = B, the number of elements in B and I must be the same!!!
    조회 수: 2 (최근 30일)
  
       이전 댓글 표시
    
Hi all,
I am very new to Matlab and I am trying to define a variable V to be any number >=700 within the following for loop:
    for i = 1:29   
    disp(i) = norm([p1(1,i+1),p1(2,i+1)]-[p1(1,i),p1(2,i)])*1000;
    V = randn(1x29);
    v >= 700;
    CL(i) = (W(i).*g)./(0.5*density*(V.^2)*S);
    CD(i) = CDo + ((CL(i).^2)/(3.14*AR*e));
    T = ((CD(i)/CL(i))*(W(i)*g))/1000;   
    Wf(i) = SFC*T*(disp(i)/V);
    W(i+1) = W(i)-Wf(i);
    end
I have tried defining V to be a random (1x29) matrix but I get the following error:
In an assignment A(I) = B, the number of elements in B and I must be the same.
Error in trial (line 38)
    CL(i) = (W(i).*g)./(0.5*density*(V.^2)*S);
Can anybody please help?
댓글 수: 0
채택된 답변
  Image Analyst
      
      
 2014년 10월 8일
        CL(i) is a single number, the i'th element of CL. You're trying to stuff a whole 29 element array into a space that can hold only a single number. Perhaps you want this???
CL(i) = (W(i).*g)./(0.5*density*(V(i).^2)*S);
If g, density, and S are also arrays, then you'd need to add (i) following them also, as well as having .* in front of S(i).
댓글 수: 4
  Image Analyst
      
      
 2014년 10월 9일
				You're welcome. Could you go ahead and officially mark the answer as "Accepted" then? Thanks in advance.
추가 답변 (0개)
참고 항목
카테고리
				Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

