Is there a limitation to using the RESHAPE command in a for loop?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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.
0 comentarios
Respuesta aceptada
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.
Más respuestas (0)
Ver también
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!