- both are the same size on that dimension,
- one of them has size one (in which case it will be expanded to the size of the other array).
Non-singleton dimensions of the two input arrays must match each other using bsxfun
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi,
I have 4D data with dimensions mydata=[ 156 , 192 , 26 , 41]. I have also an array of values which I import in Matlab as .txt file. The array has dimensions array=[1, 41].
I am using the bsxfun like this:
mydata = bsxfun(@rdivide, mydata, mydata(:,:,:,find(array==0)));
I am keep getting the error but I don't understand why. Can someone help with that?
Thanks a lot in advanced.
0 Kommentare
Akzeptierte Antwort
Stephen23
am 14 Dez. 2018
Bearbeitet: Stephen23
am 14 Dez. 2018
The problem lies in the last dimension (here I marked the first three dimensions with r,c,p because their actual numeric values are unimportant for this discussion):
size(mydata)
ans = r c p 41
But apparently you have more than one (or zero) matches for your logical comparison:
find(array==0) % btw, FIND is not required here.
Lets say, for example, that your logical comparison has four matches, then you will get four indices... and so the second array input to bsxfun will have size (r,c,p,4), where r,c,p are exactly the same as mydata. But remember that mydata, the first array input to bsxfun, has size (r,c,p,41).
bsxfun allows two possible cases for any one dimension of the two input arrays:
Do your arrays fit either of these two conditions? (hint: no).
Ignoring the other dimensions might make this clearer: it is as if you are trying to operate on two vectors with different lengths, e.g.:
[1,2,3] + [9,8,7,6,5,4]
If they were both the same length or one of them were scalar it would work, otherwise MATLAB will throw an error.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!