필터 지우기
필터 지우기

Error: Assignment has more non-singleton rhs dimensions than non-singleton subscripts

조회 수: 2 (최근 30일)
I have the following matlab code in which I have 6 variables(=n_gc) with the min and max limit as "it.min_gc" and "it.max_gc" respectively. And each variable has 3(=M_g) values. From that I want to produce different combination i.e., as I have 729 combination (=3^6). So I used "ndgrid" operation and it produced the result which is stored in 6 variables(s1 u1 u2 ts vs vw) i.e., for example values stored in s1 is s1(1) to s1(729). But when I want to produce 729 combination again (i.e., when p=2) and try to store it, it shows the error "Assignment has more non-singleton rhs dimensions than non-singleton subscripts"
for k = 1:p
for a = 1:n_gc
gc(k,a,:) = (it.min_gc(k,a):((it.max_gc(k,a)-it.min_gc(k,a))/...
(M_g-1)):it.max_gc(k,a));
end
[s1(k,:) u1(k,:) u2(k,:) ts(k,:) vs(k,:) vw(k,:)] = ndgrid(gc(k,1,:),...
gc(k,2,:),gc(k,3,:),gc(k,4,:),gc(k,5,:),gc(k,6,:));
end
Please can anyone help me to resolve this issue?

채택된 답변

Walter Roberson
Walter Roberson 2012년 2월 2일
  1. it appears to me that you would be better rewriting your gc setting code in terms of linspace()
  2. I think you might have to use squeeze() on each of the arguments to ndgrid(). This could, however, be avoided if you were to move k to the last subscript.
  3. ndgrid is not going to be producing vectors, but you are trying to store the output as vectors
  4. it might be easier to rewrite in terms of cell arrays, especially if you do not have a strong need to have individual names s1, u1, etc..
  댓글 수: 14
Walter Roberson
Walter Roberson 2012년 2월 5일
Are you running this as a script or in a function? If you were running it in a script, then because you would already have had the variables such as s1 and u1 in your workspace, you would have had trouble using those variables as cell arrays. You should use a function to protect against this kind of problem. Or at least at the top of your code, put in a "clear" statement
clear k a gc s1 u1 u2 ts vs vw
Matt Learner
Matt Learner 2012년 2월 5일
Its a function, I am using the inputs (said in my last comment) to run this function.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB Mobile Fundamentals에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by