transforming a script for a matrix to a cell array
이전 댓글 표시
a = randi(50,600,9);
mx = randi(50,60,1);
mn = randi(50,60,1);
b = reshape(a(:,7),10,[]).';
q = bsxfun(@minus,b,mx);
%q = bsxfun(@rdivide,q,mx-mn);
%q = reshape(q.',[],1);
How can I apply this code which has been designed for a matrix table to a cell array?
Imagine the following
a = { rand(6000,7); rand(3600,7); rand(600,7); };
mx = {randi(50,600,1); randi(360,60,1); randi(50,60,1)}
mn = {randi(50,600,1); randi(360,60,1); randi(50,60,1)}
댓글 수: 12
Note that a table is another data class in MATLAB, and is neither a cell array nor a numeric array .
In your question you give examples of cell arrays a, mx and mn, all of which have dimensions 3x1.
Now you state that a should be 1x3, and both of mx and mn should be 3x61.
I understand that the numbers of rows of the numeric arrays contained within mx and mn is a divisor of those within a. We dealt with this in an earlier question. However we now have a different issue: what kind of operation do you wish to perform on the arrays a, mn and mx ? Currently these cell arrays are all different sizes... do we ignore the extra elements, replicate the smaller arrays, or perform our operation on a scalar of the small array but an array-subset of the larger array?
Stephen23
2014년 12월 2일
Why must the numeric arrays in a contain six unused columns?
AA
2014년 12월 2일
Okay, so the six unused columns are not a problem for you :)
Lets sort out the cell array sizes: The most recent definition is that a is 1x3, and mx and mn are each 3x61. Usually one tries to operate on corresponding elements (ie F(a(x,y),mn(x,y)), but as you can see if x>1 or y>3 then we run out of a, as it is simply not the same size as mx or mn.
It is not clear to me why you need the cell arrays at all. I have a feeling that these might be making the issue more complicated than it needs to be... it really would be much easier to create the results using numeric arrays, and split it into a cell array afterwards (iff required).
So a is actually size 3x1, and not 1x3 as you stated earlier?
This might seem like a pedantic point, but MATLAB was primarily written by (and for) mathematicians, and in mathematics, array dimensions really matter...
This is quite different to some languages, where they will assume that you want to match dimensions that seem to be similar... this is simply not strict enough for mathematicians ;)
AA
2014년 12월 2일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
