applying formula across various matrices

1 view (last 30 days)
AA
AA on 11 Nov 2014
Answered: AA on 14 Nov 2014
Hi guys, I have a complex problem.
I have a cell array b (1x100 cell). The cells contain matrices with various row numbers but the same column number. Cell one has a matrix that has 3755940 x 7 double b{1,1}, cell two has a matrix that has 1878000x7 double b{1,2}, and so on. All these matrices are divisible by 60. Another cell array mx (100x61 cell) and mn (100x 61 cells) have matrices that contain the maximum and minimum values of the consecutive 60 rows of cell array b.
The variables mx and mn were created with the following code: a=cell array
b=cellfun(@(x) [x; repmat(x(end,:),-mod(size(x,1),-60),1)],a,'un',0);
n = 61;
for k = 1:n
for i=1:length(b)
c = circshift(b{i}, [-(k-1) 0]);
mn(i,k)={max(reshape(c(:,4),60,[])).'};
mx(i,k)={min(reshape(c(:,5),60,[])).'};
end
end
My question is the following: Lets choose the first cell of cell array b which is a matrix (3755940 x7 double)b{1,1}. I want an additional column to be added to this matrix. This column should be a calculation containing the formula starting from the first row with a change after every 60 rows:
(Column 7 row 1 of b{1,1}- Column 1 row 1 of mn {1,1})/( Column 1 row 1 of mn {1,1}-Column 1 row 1 of mn {1,1})
(Column 7 row 2 of b{1,1}- Column 1 row 1 of mn {1,1})/( Column 1 row 1 of mn {1,1}-Column 1 row 1 of mn {1,1})
(Column 7 row 3 of b{1,1}- Column 1 row 1 of mn {1,1})/( Column 1 row 1 of mn {1,1}-Column 1 row 1 of mn {1,1})
(Column 7 row 4 of b{1,1}- Column 1 row 1 of mn {1,1})/( Column 1 row 1 of mn {1,1}-Column 1 row 1 of mn {1,1})
..
(Column 7 row 59 of b{1,1}- Column 1 row 1 of mn {1,1})/( Column 1 row 1 of mn {1,1}-Column 1 row 1 of mn {1,1})
(Column 7 row 60 of b{1,1}- Column 1 row 1 of mn {1,1})/( Column 1 row 1 of mn {1,1}-Column 1 row 1 of mn {1,1})
(Column 7 row 61 of b{1,1}- Column 1 row 2 of mn {1,1})/( Column 1 row 2of mn {1,1}-Column 1 row 2 of mn {1,1}) (NOTE the switch of the row number mn and mx after 60 rows)
(Column 7 row 62 of b{1,1}- Column 1 row 2 of mn {1,1})/( Column 1 row 2of mn {1,1}-Column 1 row 2 of mn {1,1})
…….
Until all rows are covered
So column 7 row x of b{1,1} is increasing by n+1 whereas the row number of mn/mx{1,1} is increasing by n+1 after 60 rows.
After that, an additional column should to be added to this matrix b{1,1}. This column should again be a calculation containing the formula starting from the first row with a change after every 60 rows but in a different manner:
(Column 7 row 1 of b{1,1}- Column 1 row 1 of mn {1,2})/( Column 1 row 1 of mn {1,2}-Column 1 row 1 of mn {1,2})
(Column 7 row 2 of b{1,1}- Column 1 row 1 of mn {1,2})/( Column 1 row 1 of mn {1,2}-Column 1 row 1 of mn {1,2})
(Column 7 row 3 of b{1,1}- Column 1 row 1 of mn {1,2})/( Column 1 row 1 of mn {1,2}-Column 1 row 1 of mn {1,2)
Same thing again
…….
Until all rows are covered
So column 7 row x of b{1,1} is increasing by n+1 whereas the row number of mn/mx{1,2} is increasing by n+1 after 60 rows. I want this loop to be repeated until mn/mx{1,61} are covered. Once this step is done I want the same to be repeated for b{1,2} and mn/mx{2,1}-mn/mx{2,61]. Then b{1,3} and mn/mx{3,1}-mn/mx{3,61]…………until b{1,100} and mn/mx{100,1}-mn/mx{100,61}
Thanks
  1 Comment
dpb
dpb on 12 Nov 2014
I suggest a SMALL sample problem that can show input and expected outputs to make the explanation simpler. As is, my eyes glazed over before I could even finish trying to straighten out the formatting enough to at least get stuff on separate lines.
Use miniature arrays, a repeat of three is just as good as 60...

Sign in to comment.

Answers (4)

Star Strider
Star Strider on 13 Nov 2014
Maybe I’m missing something in your problem statement, but wouldn’t:
(Column 7 row 1 of b{1,1}- Column 1 row 1 of mn {1,1})/( Column 1 row 1 of mn {1,1}-Column 1 row 1 of mn {1,1})
etc., evaluate to infinity in every calculation? The denominator will be zero as I read it.
  1 Comment
AA
AA on 13 Nov 2014
you are right. I made a stupid mistake. I meant mx instead of mn. I will repost

Sign in to comment.


AA
AA on 13 Nov 2014
ok let me give you a better example to clarify what I want to do: Assume the following array
a={rand(3755940,7); rand(1877958,7)};
b=cellfun(@(x) [x; repmat(x(end,:),-mod(size(x,1),-60),1)],a,'un',0);
n = 61;
for k = 1:n
for i=1:length(b)
c = circshift(b{i}, [-(k-1) 0]);
mn(i,k)={max(reshape(c(:,4),60,[])).'};
mx(i,k)={min(reshape(c(:,5),60,[])).'};
end
end
My question is the following: Lets choose the first cell of cell array b which is a matrix (3755940 x7 double)b{1,1}. I want an additional column to be added to this matrix. This column should be a calculation containing the formula starting from the first row with a change after every 60 rows:
(Column 7 row 1 of b{1,1}- Column 1 row 1 of mn {1,1})/( Column 1 row 1 of mn {1,1}-Column 1 row 1 of mn {1,1})
(Column 7 row 2 of b{1,1}- Column 1 row 1 of mn {1,1})/( Column 1 row 1 of mn {1,1}-Column 1 row 1 of mn {1,1})
(Column 7 row 3 of b{1,1}- Column 1 row 1 of mn {1,1})/( Column 1 row 1 of mn {1,1}-Column 1 row 1 of mn {1,1})
(Column 7 row 4 of b{1,1}- Column 1 row 1 of mn {1,1})/( Column 1 row 1 of mn {1,1}-Column 1 row 1 of mn {1,1})
..
(Column 7 row 59 of b{1,1}- Column 1 row 1 of mn {1,1})/( Column 1 row 1 of mn {1,1}-Column 1 row 1 of mn {1,1})
(Column 7 row 60 of b{1,1}- Column 1 row 1 of mn {1,1})/( Column 1 row 1 of mn {1,1}-Column 1 row 1 of mn {1,1})
(Column 7 row 61 of b{1,1}- Column 1 row 2 of mn {1,1})/( Column 1 row 2of mn {1,1}-Column 1 row 2 of mn {1,1}) (NOTE the switch of the row number mn and mx after 60 rows)
(Column 7 row 62 of b{1,1}- Column 1 row 2 of mn {1,1})/( Column 1 row 2of mn {1,1}-Column 1 row 2 of mn {1,1})
…….
Until all rows are covered
So column 7 row x of b{1,1} is increasing by n+1 whereas the row number of mn/mx{1,1} is increasing by n+1 after 60 rows.

AA
AA on 13 Nov 2014
Edited: AA on 13 Nov 2014
ok let me give you a better example to clarify what I want to do: Assume the following array
a={rand(3755940,7); rand(1877958,7)};
b=cellfun(@(x) [x; repmat(x(end,:),-mod(size(x,1),-60),1)],a,'un',0);
n = 61;
for k = 1:n
for i=1:length(b)
c = circshift(b{i}, [-(k-1) 0]);
mn(i,k)={max(reshape(c(:,4),60,[])).'};
mx(i,k)={min(reshape(c(:,5),60,[])).'};
end
end
*My question is the following: Lets choose the first cell of cell array b which is a matrix (3755940 x7 double)b{1,1}. I want an additional column to be added to this matrix. This column should be a calculation containing the formula starting from the first row with a change after every 60 rows:*
(Column 7 row 1 of b{1,1}- Column 1 row 1 of mn {1,1})/( Column 1 row 1 of mx {1,1}-Column 1 row 1 of mn {1,1})
(Column 7 row 2 of b{1,1}- Column 1 row 1 of mn {1,1})/( Column 1 row 1 of mx {1,1}-Column 1 row 1 of mn {1,1})
(Column 7 row 3 of b{1,1}- Column 1 row 1 of mn {1,1})/( Column 1 row 1 of mx {1,1}-Column 1 row 1 of mn {1,1})
(Column 7 row 4 of b{1,1}- Column 1 row 1 of mn {1,1})/( Column 1 row 1 of mx {1,1}-Column 1 row 1 of mn {1,1})
..
(Column 7 row 59 of b{1,1}- Column 1 row 1 of mn {1,1})/( Column 1 row 1 of mx {1,1}-Column 1 row 1 of mn {1,1})
(Column 7 row 60 of b{1,1}- Column 1 row 1 of mn {1,1})/( Column 1 row 1 of mx {1,1}-Column 1 row 1 of mn {1,1})
(Column 7 row 61 of b{1,1}- Column 1 row 2 of mn {1,1})/( Column 1 row 2of mx {1,1}-Column 1 row 2 of mn {1,1}) (NOTE the switch of the row number mn and mx after 60 rows)
(Column 7 row 62 of b{1,1}- Column 1 row 2 of mn {1,1})/( Column 1 row 2of mx {1,1}-Column 1 row 2 of mn {1,1})
…….
Until all rows are covered
So column 7 row x of b{1,1} is increasing by n+1 whereas the row number of mn/mx{1,1} is increasing by n+1 after 60 rows.

AA
AA on 14 Nov 2014
any advice?

Categories

Find more on Scope Variables and Generate Names in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!