Looping through csv Data Sets
8 次查看(过去 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
0 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!