Plot Specific Info from a data file?

2 ビュー (過去 30 日間)
Samantha Farmer
Samantha Farmer 2018 年 10 月 11 日
編集済み: jonas 2018 年 10 月 11 日
So here is the problem: A file called avehighs.dat stores the average high temperatures for each month for a year(rounded to integers). The first column of the data stores the zip code, the 2nd to 13thcolumns store 12 temperatures. For example, the file might store: 65211 33 37 42 45 53 72 82 79 66 55 46 41 65201 29 33 41 46 52 66 77 88 68 55 48 39 65203 55 62 68 72 75 79 83 89 85 80 77 65 Write a function that will take in one input argument: the zip code. This function will first read in the data file, then find the line corresponding to the zip code, and plot the temperatures for all 12 months. The axis labels and titles should be as shown. The figure title should show the zip-code.
I'm having some trouble plotting the right data. Here is my code, but it isn't plotting the right thing.
% code
function []=ShowTemp(z)
data=importdata('C:\Users\samfa\OneDrive\Documents\avehighs.dat');
plot(data(:,2,end))
xlabel('Month')
ylabel('Ave High Temps')
title(['Location ',num2str(z)])
end
Any ideas on how to fix the plot? I thought the (:,2,end) would plot the data from the second column on, but I think I have to put z in there somewhere?

回答 (1 件)

jonas
jonas 2018 年 10 月 11 日
編集済み: jonas 2018 年 10 月 11 日
2nd and onward is written as
2:end
What you wrote is interpreted as 'each row, 2nd column and last value in the 3rd dimension (z) '.

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by