Reduce size of multidimensional array
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
Hello,
I have a multidimensional array size = 220 x 46 x 10 x 4 x2 . I would like to combine all of the data in the third dimension so that way I end up with a 4-dimesional array. Any help is greatly appreciated.
Take care and stay well!
採用された回答
James Tursa
2021 年 2 月 8 日
One way using summing:
result = squeeze(sum(your_array,3));
7 件のコメント
Hi! Thanks so much for your speedy help. I did this and now the size of my array is: 220 46 2 4. However, I want all of the raw data from the 3rd dimension. So wouldn't one of my dimesions then have to be expanded by an order of 10 (e.g., 2200 46 2 4). Please let me know if I'm misunderstanding what is happening.
So how do you want the data combined? Another method that retains the raw data would be:
result = reshape(your_array,220,46,10*4,2)
which combines the 3rd and 4th dimensions into one dimension. But it isn't clear how you want the array reduced from 5 dimensions to 4.
Hi James, Thank you for the follow-up. I would like to take all ten trials in the third dimension and combine them so they are vertically stacked in the first dimension (220*10), giving me a 2200 x 46 x 4 x 2 matrix. I will be doing this for a series of data with varying trial numbers so if you could help me to adapt the code for the varying lengths of dimension 3 that would also be greatly appreciated.
Hi James - I think I figured it out. I created vectors that will update the sizes based on the participant (e.g., x = reshape(trialTimecourses, maxTL*maxTrials, data.nChans, nHb, data.nConds). Thank you so much for your help!
Maybe this does what you want?
result = reshape(permute(your_array,[1 3 2 4 5]),2200,46,4,2)
Yes! Thank you! I did not realize the arrays had to be next to eachother before applying the reshape function!
James Tursa
2021 年 2 月 9 日
Yes. Reshape does not change the order of the data in memory. You will often need to use another function first such as permute or transpose etc. to rearrange the data in memory before applying the reshape.
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Creating and Concatenating Matrices についてさらに検索
参考
2021 年 2 月 8 日
2021 年 2 月 9 日
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
