reshaping to display the same result of a function

I want the following function to be reshaped in a different manner:
for i=1:length(b)
mn(i)={min(reshape(b{i}(:,5),60,[])).'};
mx(i)={max(reshape(b{i}(:,6),60,[])).'};
end
This code breaks the rows into a group of 60 and then finds the max or min value. I, however, would like to reshape in such a way that the min value is found for the 60 rows and then the min value is given for each of these 60 rows rather than giving one value. For instance,
1
3
4
5
67
8
The min value of this column is 1. I want the result to be displayed in such a manner:
1 1
3 1
4 1
5 1
67 1
8 1

 Accepted Answer

My initial answer was written to do that but then I looked at the code you had written and followed your lead of the two vectors... :)
for i=1:length(b)
mnmx(i)={[min(reshape(b{i}(:,5),60,[])).' ...
max(reshape(b{i}(:,6),60,[])).']};
end
Concatenate the two column vectors before turning into a cell.

4 Comments

it still gives me the same problem. Maybe I didnt explain it very well. My cell array consists of several matrices ie.
b=
[1878000x7 double]
[1252020x7 double].
When I use the function to get the max or min value then I get a cell array with matrices of a different dimension:
mn = [31300x1 double] [20867x1 double]
mx = [31300x1 double] [20867x1 double].
I want the result to be displayed as 1878000x1 double and 1252020x1 double. The max or min value should be repeated 60 times for the corresponding row:
or instance,
1
3
4
5
67
8
The min value of this column is 1. I want the result to be displayed in such a manner:
1 1
3 1
4 1
5 1
67 1
8 1
That seems like a lot of wasted space to store duplicated information. Why don't you just store the two min/max vectors and the count (if it's variable)?
With arrays of this size you can't be looking at them physically so what is the step at which you next need these arrays of 60X the needed size to keep the information contained within them?
Certainly you can repmat the values 60 times but don't see why you would want to...
reshape(repmat(mn{i}.',60,1),1,[]).'
Again, to get there in the right order one must think of Matlab internal storage order by column. Duplicate rows N times then recast that array into the column vector to preserve order. NB: again, of course, you've got the mod 60 problem of the initial array lengths to deal with however is appropriate.
You are totally right. I want to do this repetition as i have more calculations planned for later on.
So, what specific calculations actually require the duplicated values?
Specifically,
doc bsxfun
for one particular case of singleton expansion to avoid the explicit arrays.
We can't suggest other alternatives if hide the information on what the next step is from us, though... :(

Sign in to comment.

More Answers (0)

Categories

Find more on Operators and Elementary Operations in Help Center and File Exchange

Asked:

AA
on 9 Nov 2014

Commented:

dpb
on 9 Nov 2014

Community Treasure Hunt

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

Start Hunting!