could anyone tell me how to store the result of each iteration in an array for the following code
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
code:
t=4;
r=6;
for it=1:4
output(t,r)=overall_throughput;
output_it(t,r,it)=output(t,r);
end
Accepted Answer
Walter Roberson
on 10 Apr 2018
t=4;
r=6;
for it=1:4
output(t,r)=overall_throughput;
output_it(t,r,it)=output(t,r);
all_output{it} = output;
all_output_it{it} = output_it;
end
Now a complete record of the results of the iterations is stored in all_output and all_output_it
5 Comments
Prabha Kumaresan
on 12 Apr 2018
Edited: Walter Roberson
on 12 Apr 2018
When i run the following code i am getting error
Conversion to cell from double is not
possible.
Bmax=3000;
noise=10;
A=[0 0 0 0 0.0447 0
0 0 0 0 0.0294 0]
B=[0 0 0 0 0.2428 0
0 0 0 0 0.4424 0]
A=[0 0 1.9728 0 0 0
0 0 0.0000 0 0 0]
B=[0 0 0.1971 0 0 0
0 0 0.2703 0 0 0]
A=[0.2373 0.2169 0 0.1979 0 0.2098
0.0174 0.0186 0 0.0214 0 0.0249]
B=[0.2160 0.7904 0 0.4386 0 0.8620
0.3774 0.9493 0 0.8335 0 0.9899]
N = length(A) ;
throughput = cell(N,1) ;
for v =1:size(B,2)
for u =1:size(A,1)
for k =1:N
throughput{k}=throughput(u,v)
throughput(u,v) =(Bmax.*log2(1+(((A(u,v)).*(B(u,v))/(noise+sum(B(1:u-1,v)).*A(u,v))))))
end
end
end
could you please help me on this.
On the line
throughput{k}=throughput(u,v)
you are taking the content of the cell array throughput(u,v) and placing the cell array as the content of throughput(k, 1), resulting in nested cell arrays.
On the line
throughput(u,v) =(Bmax.*log2(1+(((A(u,v)).*(B(u,v))/(noise+sum(B(1:u-1,v)).*A(u,v))))))
you are taking the numeric value after the "=" and trying to store it as if it were a cell array into location throughput(u,v) .
Perhaps instead of using throughput(u,v) in those places, you might want throughput{u,v}
And it is really not recommended to mix linear indexing {k} with two-dimensional indexing in the same group of code.
If you end up mixing () notation on a cell and {} notation on the cell, then you should double-check the code to be sure you really want to work with the content as being containers, which is () notation, or if you want to work with what is inside the containers, which is {} notation. Sometimes it makes sense to use both in the same block of code, but more often it indicates that cells are being misused.
Prabha Kumaresan
on 12 Apr 2018
Edited: Walter Roberson
on 12 Apr 2018
ok. could you tell me is there any other way to solve the issue for the following code:
A=[0 0 0 0 0.0447 0
0 0 0 0 0.0294 0]
B=[0 0 0 0 0.2428 0
0 0 0 0 0.4424 0]
A=[0 0 1.9728 0 0 0
0 0 0.0000 0 0 0]
B=[0 0 0.1971 0 0 0
0 0 0.2703 0 0 0]
A=[0.2373 0.2169 0 0.1979 0 0.2098
0.0174 0.0186 0 0.0214 0 0.0249]
B=[0.2160 0.7904 0 0.4386 0 0.8620
0.3774 0.9493 0 0.8335 0 0.9899]
for v =1:size(B,2)
for u =1:size(A,1)
throughput(u,v) =(Bmax.*log2(1+(((A(u,v)).*(B(u,v))/(noise+sum(B(1:u-1,v)).*A(u,v))))))
end
end
throughput{u,v} = ...
I have modified the line to
throughput{u,v} =(C.*log2(1+(((A{u,v}).*(B{u,v})/(w+sum(B(1:u-1,v)).*A{u,v})))))
but still i am getting error. Cell contents reference from a non-cell array object.
More Answers (0)
Categories
Find more on Mathematics in Help Center and File Exchange
See Also
on 10 Apr 2018
on 12 Apr 2018
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)