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

1 vue (au cours des 30 derniers jours)
Brad
Brad le 18 Juil 2013
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.

Réponse acceptée

Sean de Wolski
Sean de Wolski le 18 Juil 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 commentaire
Brad
Brad le 18 Juil 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!!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by