フィルターのクリア

reshape+loop error

3 ビュー (過去 30 日間)
Mandy Guo
Mandy Guo 2015 年 8 月 14 日
コメント済み: Walter Roberson 2015 年 8 月 14 日
hi, i am trying to create a loop but I got this error message: Error using reshape Size arguments must be integer scalars. Can I ask how to solve it? thanks.
for i=1:120
d{i,3}=reshape(d{i,1},m(i,4),m(i,2));
end

回答 (1 件)

Walter Roberson
Walter Roberson 2015 年 8 月 14 日
d{i,3}=reshape(d{i,1},m(:,4),m(:,2)); tries to use the content of all of column 4 of m as the first dimension, and the content of all of column 2 of m as the second dimension. If m has more than one column then m(:,4) and m(:,2) would come out as vectors, and it is not allowed to reshape() to a vector of sizes. If you are certain that m has only 1 column then why not explicitly code m(1,4) and m(1,2) ?
Are you sure that m has sizes in it, and not data?
  2 件のコメント
Mandy Guo
Mandy Guo 2015 年 8 月 14 日
編集済み: Mandy Guo 2015 年 8 月 14 日
hi, b actually contains 120 cells. I need to reshape them one by one and therefore it is 120 times. However, the question here is different cells have different lengths. thats why I created a loop for this.m (i,2) and m(i,4) represent the num of columns and rows of new matrix. Can you help me develop this code? many thanks
Walter Roberson
Walter Roberson 2015 年 8 月 14 日
Your revised code looks appropriate, provided that the m values are integer values and that m(i,4)*m(i,2) = numel(d{i,1})

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by