フィルターのクリア

Looping through csv Data Sets

4 ビュー (過去 30 日間)
Amanda
Amanda 2013 年 5 月 9 日
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 件)

カテゴリ

Help Center および File ExchangeBartlett についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by