MATLAB Answers

Translated by

このページのコンテンツは英語から自動翻訳されています。自動翻訳をオフにする場合は「<a class="turn_off_mt" href="#" onclick="window._kiq.push(['set', { 'event': 'Turn off MT' }]);">ここ</a>」をクリックしてください。


Why are my array dimensions being changed?

Scott Hunter さんによって質問されました 2019 年 6 月 19 日 13:13
最新アクティビティ Star Strider
さんによって コメントされました 2019 年 6 月 19 日 15:51
I have a 3D array cart = s x 3 x p double, where s and p are variables chosen as integers by an optimiser. I'm converting this array to the array sph = s x 3 x p through cart2sph;
[sph(:,1,:), sph(:,2,:), sph(:,3,:)] = cart2sph(cart(:,1,:), cart(:,2,:), cart(:,3,:));
This works fine, unless the case happens to be the optimiser choses to set s = 1. Instead of outputting sph = 1 x 3 x p, it outputs sph = p x 3, which causes issues with my code calling the function I do this in.
It only happens with s, I've tried limiting p to 1 only it seems to run fine, can anyone help?

  0 件のコメント

サインイン to comment.

1 件の回答

回答者: Star Strider
2019 年 6 月 19 日 13:40

You can add the missing dimension.
Experiment with this:
x1 = rand(3,4);
x2(1,:,:) = x1;
To check:
x1s = size(x1)
x2s = size(x2)
x1s =
3 4
x2s =
1 3 4
You will have to set up the appropriate tests to check the dimensions, then do the assignment.

  4 件のコメント

Star Strider
2019 年 6 月 19 日 15:05
That wasn’t in the code you posted, so I didn’t see it.
The optimiser could be using the squeeze function to eliminate the singleton dimensions. If that’s the situation, you would have to add it back.
Scott Hunter 2019 年 6 月 19 日 15:43
No no as in I adder it after your comment, it gave me the idea. Thanks!
Star Strider
2019 年 6 月 19 日 15:51
As always, my pleasure!

サインイン to comment.

Translated by