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

1 view (last 30 days)
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.

Accepted Answer

Sean de Wolski
Sean de Wolski on 18 Jul 2013
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 Comment
Brad
Brad on 18 Jul 2013
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!!

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!