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

1 visualización (últimos 30 días)
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.

Respuesta aceptada

Sean de Wolski
Sean de Wolski el 18 de Jul. de 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 comentario
Brad
Brad el 18 de Jul. de 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!!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Programming en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by