Comparing matrices of different dimensions
古いコメントを表示
I have 3 matrices, one is a 1x301 array,A, one is a scalar value,B, and the 3rd is 10x10x10 array,C. I need to be able to do: A-B/C.
I've tried it using meshgrid by doing: [An, Bn, Cn] = meshgrid(A,B,C) following it up by F = An - (Bn ./ Cn); so that a matrix can be output containing the values of the sum for each element.
I'm unsure whether this is the right method or the best way to go about it
2 件のコメント
Image Analyst
2017 年 12 月 16 日
I'm not sure what you want to do. A has 301 values while C has a thousand values. In what way do you want to combine them? For example, what is the last element of F? The 301st? The 1000th? What elements of A and C would go into making up the last value of F? Please spell it out explicitly.
mathman
2017 年 12 月 16 日
回答 (1 件)
Image Analyst
2017 年 12 月 16 日
So what do you plan on doing with elements 302 - 1000 of C? Ignore them? And in what order do you plan on taking the first 301 elements of C?
lastElement = max([numel(A), numel(B), numel(C)]);
F = A(1:lastElement) - (B(1:lastElement) ./ C(1:lastElement));
this takes c in column major order.
カテゴリ
ヘルプ センター および File Exchange で Elementary Math についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!