how can I plot particular rows of a matrix?

43 ビュー (過去 30 日間)
Tran Trang
Tran Trang 2019 年 7 月 10 日
I have a 7208x34 matrix which columns [3 32] represent price data over the 1961-1990 period. And a row array 1x30 (the row array indicates the years from 1961 to 1990). I want to plot time series of 68 rows (i.e. grouping by cities) for each goods over the 1961-1990 period, against the 1x30 row array (years). Something looks like this:
Goods city_name price_year1961 price_year1962…
A city1 0.5
A city2 0.7
.
.
.
A city68 0.9
B city1 0.4
B city2 0.7
.
.
.
B city68 0.9
and a row vector represents the years [1961:1990].
Thank you very much!

採用された回答

Basil C.
Basil C. 2019 年 7 月 10 日
編集済み: Basil C. 2019 年 7 月 11 日
You could first start by reading the columns into an array
data=readtable('Price.txt');
prices=data(:,3:30);
n=5; %in order to plot the data for city 5
city_data=prices(n:68:end,:)
year=1961:1990;
If you want to plot for individual Good
good=3 % for the data of Good 3
plot(year,city_data(good,:))
For all the goods
for i=1:size(city_data,1)
plot(year,city_data(i,:))
hold on
end

その他の回答 (2 件)

KSSV
KSSV 2019 年 7 月 10 日
If A is your data...and you want to plot ith row; use
plot(A(i,:))
  1 件のコメント
ogheneochuko oyaide
ogheneochuko oyaide 2022 年 8 月 25 日
bro. you are good. thanks

サインインしてコメントする。


Tran Trang
Tran Trang 2019 年 7 月 10 日
編集済み: Tran Trang 2019 年 7 月 10 日
Hi B Matlabi,
Thank you for your reply. should it be city_data = prices(n:68:end,:), instead of city_data = prices(n:n:end,:), as the city repeats after 68 rows?
And how can I plot all the goods but with each plot for each good?
Thank you.
  2 件のコメント
Basil C.
Basil C. 2019 年 7 月 11 日
Yes you are correct, it should be
city_data = prices(n:68:end,:)
In order to plot all the goods but with each plot for each good at once you could try the subplot function
Tran Trang
Tran Trang 2019 年 7 月 11 日
Thank you very much!

サインインしてコメントする。

カテゴリ

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

Translated by