Is there a limitation to using the RESHAPE command in a for loop?

1 回表示 (過去 30 日間)
Brad
Brad 2013 年 7 月 18 日
I have the following block of code:
for BlockId = 1 : NumBlocks
if isempty(bufferSplit{BlockId})
continue
end
% Parse out the BER State Time
exp = 'State Time:\s+([\d:\.]+).\s+\(([\d.]+)\).';
tokens = regexp(bufferSplit{BlockId}, exp, 'tokens');
BER_State_Data = reshape(str2double([tokens{:}]), 2, []).';
end
When I try to execute this, MATLAB generates the following error message:
Error using reshape Product of known dimensions, 2, not divisible into total number of elements, 1.
Error in AC_Measurement (line 37) BER_State_Data = reshape(str2double([tokens{:}]), 2, []).';
So I replaced the last line with the following;
BER_State_Data = reshape(str2double([tokens{:}]), 1, []).';
The error goes away, but now I’m placing the state time data in a single column versus the required 2.
In reviewing the documentation pertaining to the RESHAPE command I don’t know if I’m misinterpreting the use of the command or if my loop is messed up. But I do know that if I run the code outside of a loop (against a single block of data, I get the data in 2 columns.
Any inputs are appreciated. Thanks.

採用された回答

Sean de Wolski
Sean de Wolski 2013 年 7 月 18 日
dbstop if error
Then run your code. This will stop with the debugger when the error occurs and will allow you to see the inputs to reshape(). Apparently the sizes are not consistent.
  1 件のコメント
Brad
Brad 2013 年 7 月 18 日
Sean, I can't tell you the exact number of times I've stepped through this loop and didn't see a < 0 x0 cell > - until now!!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by