Info
Questa domanda è chiusa. Riaprila per modificarla o per rispondere.
Trouble making a matrix out of accessed data
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
I have a 1x80 structure with a field called 'Task'.
The 'Task' field can either be a or b.
I want to construct a TaskType matrix that is 1x80, that basically says
if Task=='a', then make the corresponding matrix value 1.
if Task=='b', then make the corresponding matrix value 2.
if neither, then make the matrix value 3.
Here's my code so far:
for x=1:length(Structure)
if Structure(x).Task=='a'
TaskType(x)=1;
elseif Structure(x).Task=='b'
TaskType(x)=2;
else
TaskType(x)=3;
end
end
My code is returning 'matrix dimensions must agree.'
0 Commenti
Risposte (1)
the cyclist
il 20 Ott 2015
This test worked just fine for me:
% Fill in random tasks
elements = {'a','b','c','fudge'};
tasks = elements(randi(length(elements),[1,80]));
Structure = struct('Task',tasks);
% Apply Daniel's algorithm
for x=1:length(Structure)
if Structure(x).Task=='a'
TaskType(x)=1;
elseif Structure(x).Task=='b'
TaskType(x)=2;
else
TaskType(x)=3;
end
end
0 Commenti
Questa domanda è chiusa.
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!