Storing data with 2 forloops?

When I try to extract RASI from my data:
for welke_pp=1:5
...
for i_testen=1:5
...
RASI(welke_pp,i_testen) = data_sts(welke_pp,i_testen).VideoSignals(:, strcmp('RASI', data_sts(welke_pp,i_testen).VideoSignals_headers)); %try to extract data, RASI
...
end
end
The following error occurs 'Subscripted assignment dimension mismatch.' and I don't understand why... Help?

 Respuesta aceptada

Geoff Hayes
Geoff Hayes el 29 de Dic. de 2014

1 voto

Sam - what are the dimensions of your RASI and data_sts matrices or cell arrays? What are you attempting to do with
VideoSignals(:, strcmp('RASI', data_sts(welke_pp,i_testen).VideoSignals_headers))
In the above, if the string at data_sts(welke_pp,i_testen).VideoSignals_headers is not RASI, then the strcmp returns a zero in which case you will be trying to access
VideoSignals(:,0);
which will generate an error (though not the one that you are observing).
Your error, Subscripted assignment dimension mismatch, typically means that you are attempting to assign too much (or too little) data. In your case, if RASI is a matrix, then
RASI(welke_pp,i_testen)
is a single element within that matrix, and
data_sts(welke_pp,i_testen).VideoSignals(:,1)
may be a column vector of data...and so you are attempting to assign a column vector to a single element within RASI.
Put a breakpoint at this assignment and run your code. When the debugger pauses at this line, look at what is being assigned and where you are assigning it to, and ask yourself if the assignment makes sense.

3 comentarios

Sam
Sam el 29 de Dic. de 2014
Editada: Sam el 29 de Dic. de 2014
data_sts is a 5x5struct (see attachment). Each struct contains 6 data-files (see attachment). VideoSignals is a 3D matrix. I want to extract RASI (which is a column vector with variable length). If I type:
RASI{1,i_testen} = data_sts(welke_pp,i_testen).VideoSignals(:, strcmp('RASI', data_sts(welke_pp,i_testen).VideoSignals_headers)); %try to extract data, RASI
I can extract RASI but just for the first subject until it reaches i_testen = 5. Maybe my if-statement has something to do with it?
for welke_pp=1:5
...
for i_testen=1:5
if ~( ((i_testen == 4) && (welke_pp == 1)) || ((i_testen == 4) && (welke_pp == 3)) || ((i_testen == 4) && (welke_pp == 4)) || ((i_testen == 4) && (welke_pp == 5)) );
...
RASI{1,i_testen} = data_sts(welke_pp,i_testen).VideoSignals(:, strcmp('RASI', data_sts(welke_pp,i_testen).VideoSignals_headers)); %try to extract data, RASI
...
end
end
per isakson
per isakson el 29 de Dic. de 2014
"(see attachment)" &nbsp There is no attachment
Sam
Sam el 29 de Dic. de 2014
Found it. Thanks!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Etiquetas

Preguntada:

Sam
el 29 de Dic. de 2014

Comentada:

Sam
el 29 de Dic. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by