could anyone help me to solve the issue

조회 수: 1 (최근 30일)
Prabha Kumaresan
Prabha Kumaresan 2018년 8월 16일
편집: Walter Roberson 2018년 8월 17일
I want to run the command line iwant2=max(iwant1,[],3) with respect to iterations. I tried with the following line iwant3(it)=iwant2.But i unable to get the result.Could anyone please help me on this.
  댓글 수: 8
Walter Roberson
Walter Roberson 2018년 8월 16일
We have guided you through many questions. By now we expect that you would know that we would want to see the size() of the variables at the time the problem occurred, and we would want to know which iteration the problem occurred upon.
My suspicion is that the size of the data in your cell entries is not consistent.
Prabha Kumaresan
Prabha Kumaresan 2018년 8월 17일
a=[2 4 6 8 10 12]
b=[25]
for it=1:5
for t = 1:length(a)
for r = 1:length(b)
q=1
c=1:a(t)
for s=1:numel(c)
o_th{t,r,s,q}=D;%D= (4.2440e+12) is 1x1 double
q=q+1;
iwant1(t,r,s) = sum(cell2mat(o_th(t,r,s,:)));
iwant2=max(iwant1,[],3);
iwant12(t,r,s,it)=iwant2
end
end
end
this was the code i am working on. when i run the code i am facing error. Could you please help me on this.

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

채택된 답변

Walter Roberson
Walter Roberson 2018년 8월 17일
a=[2 4 6 8 10 12]
c=1:a(t)
When t is 1, that is c=1:a(1) which is c=1:2
for s=1:numel(c)
so in the first iteration, s reaches as high as 2, and
iwant1(t,r,s) = sum(cell2mat(o_th(t,r,s,:)));
makes iwant1 into a 1 x 1 x 2 array.
iwant2=max(iwant1,[],3);
With iwant1 being 1 x 1 x 2, max() of that over the third dimension is going to give a 1 x 1 result for iwant2, and a scalar can be stored into a scalar location in
iwant12(t,r,s,it)=iwant2
Then consider when t becomes 2. The first iteration with that,
iwant1(t,r,s) = sum(cell2mat(o_th(t,r,s,:)));
is going to enlarge iwant1 from 1 x 1 x 2 into to 2 x 1 x 2 . max() of a 2 x 1 x 2 over the third dimension is going to return a 2 x 1 x 1 array, more commonly called a 2 x 1 array. And you cannot store a 2 x 1 array into a scalar location.
This is the same error we have been telling you about since... what, October or so, if not earlier?
If your different iterations are going to produce different sizes of output, then you need to use cell arrays, or you need to initialize your arrays to maximum size, initializing with a value that cannot be created otherwise, to signal locations that are "unused".
  댓글 수: 4
Stephen23
Stephen23 2018년 8월 17일
편집: Stephen23 2018년 8월 17일
@Prabha Kumaresan: you need to learn how to debug your own code. In the long run, debugging code using random strangers on the internet is not an efficient use of your time. The first things to check when code does not work are what sizes variables have, what values variables have, what classes variables have, and to check if these are appropriate for where the code fails. After using MATLAB for so long, I am sure that you could check these things yourself.
Rik
Rik 2018년 8월 17일
You should also seriously consider a course with a paid instructor. I'm suggesting a paid instructor, because they should have the time to help you individually, and focus on what are the parts that are difficult for you.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Configure Simulation Conditions에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by