Info
This question is closed. Reopen it to edit or answer.
Trouble making a matrix out of accessed data
1 view (last 30 days)
Show older comments
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 Comments
Answers (1)
the cyclist
on 20 Oct 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 Comments
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!