Looping through csv Data Sets

4 次查看(过去 30 天)
I really need someones expertise. I have a csv file like the following (extra spaces is just to make it readable):
State, Damage, Blizzards,
Texas, 2, 2,
Alabama, 1, 0,
Alabama, 0, 1,
Texas, 5, 3,
Montana, 0, 8,
Arizona, 0, 0,
Arizona, 0, 1,
Texas, 8, 5,
I have applied textread and strcmpi. Here is the goal: I need to develop a loop that gets each individual state with the associated data with the state and plot it on one plot, and repeats for each state until finish. So for loop one: Alabama has two data sets, so I need this extracted and plotted. Loop two: Texas has 3 data sets so I need this extracted and plotted. And the process repeats until all the states have been applied.
I really need a solution -- even if you are unsure.
Thanks, Amanda

采纳的回答

cr
cr 2013-5-9
编辑:cr 2013-5-9
Not sure how you want to plot, but in case you want to plot blizzards vs damage for each of the state on a separate figure, here is a way:
x = textscan(fid,'%s %d %*c %d %*c','headerlines',1) % fid corresponds to the data file.
st = x{1,1};
[stunq,idx,idy] = unique(x{1,1});
dmg = x{1,2};
bli = x{1,3};
for i = 1:length(idy)
figure(idy(i)), plot(bli(i),dmg(i),'r.'),hold on
end
  2 个评论
Amanda
Amanda 2013-5-9
WOW: Thank you so much.
cr
cr 2013-5-9
Forgot to mention the idy output in unique function. Made the changes.

请先登录,再进行评论。

更多回答(0 个)

标签

Community Treasure Hunt

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

Start Hunting!

Translated by