Amro's answer should definitely point you in the right direction, but here's the full solution spelt out for you, in case you're still having trouble:
%// Parse CSV file
[States, Damage, Blizzards] = textread(csvfilename, '%s %d %d', ...
'delimiter', ',', 'headerlines', 1);
%// Parse data and store in an array of structs
[U, ix, iu] = unique(States); %// Find unique state names
S = struct('state', U); %// Create a struct for each state
for k = 1:numel(U)
idx = (iu == k); %// Indices of rows matching current state
S(k).damage = Damage(idx); %// Add damage information
S(k).blizzards = Blizzards(idx); %// Add blizards information
end
The resulting S
is an array of structs with the fields state
, damage
and blizzards
.
Now you can loop over this array of structs, accessing fields of the corresponding struct in each iteration. For instance, to access the damage
values of Alabama (the second struct), you can do S(2).damage
.
Hope this helps!