Plotting data in mat lab based on a certain criteria
古いコメントを表示
hi i am new in mat Lab i have set of data that are constitute of station, year, month, day and Temperature i want to plot the temperature values per month in each year according to a specific station any one can help me to make this process will be appreciate best regards.
11 件のコメント
Bob Thompson
2018 年 2 月 13 日
編集済み: Bob Thompson
2018 年 2 月 13 日
How do you have your data stored? Is it in a structure, cell array, multiple individual arrays, etc.?
The general form of a 2d plot is just plot(x,y). If you have the same size datasets for all of your information then you should be able to plot any values as x and y.
wissam abdallah
2018 年 2 月 13 日
Bob Thompson
2018 年 2 月 13 日
Ok, this probably isn't the most efficient way, but I would suggest a loop through each year similar to:
hold on
for I = 1:length(year)
x = months(I);
y = temp(months(I));
plot(x,y);
clear x y;
end
You will likely have to mess around with the exact calling of month and temperature, but that is the basic method.
wissam abdallah
2018 年 2 月 13 日
編集済み: wissam abdallah
2018 年 2 月 13 日
Bob Thompson
2018 年 2 月 13 日
How do you know the relation between temperature and month? Is the temperature an array of doubles within the cell array of month?
There is a command mean() which can be used to average things, you just need to be sure you are calling the correct data.
wissam abdallah
2018 年 2 月 13 日
編集済み: wissam abdallah
2018 年 2 月 13 日
Bob Thompson
2018 年 2 月 13 日
Ok, but how do you know which temperatures are related to which month? Do you just have a giant list of temperatures, and you just have to calculate numerically where a specific day's temperature is located?
wissam abdallah
2018 年 2 月 13 日
Bob Thompson
2018 年 2 月 13 日
If possible, I would suggest reorganizing your data. If you can get it to be like the image it would be much easier to work with. This could be accomplished with cells or structures. </matlabcentral/answers/uploaded_files/104683/Data.PNG>
If that doesn't work you can run a series of loops and if statements to move through the data manually. There are 365 days in a year, except leap year. If you know how many years you have you can run a loop for each year, then a loop for each month, then a loop for each day. You can collect the data for each day in the month, then store the average of that month for the year. You can have a progressive counter contained within the loops which does not reset for each year, to advance you through the entire temperature list.
hold on % will plot all years on same plot
for year
for month
if year is ...
if month is ...
for day
I = I +1
temp(day) = temp(I)
end
mean(month) = mean(temp) % Don't actually use this naming convention, it will treat mean() as a variable
elseif month is .....
end % month check
end % leap year check
end % month
plot(months,mean(allmonths))
end % year
wissam abdallah
2018 年 2 月 13 日
Bob Thompson
2018 年 2 月 13 日
Essentially, the data structure I suggested was a series of cells and subcells to contain the necessary information. It would make indexing a pain, but it would be less challenging than large arrays.
In response to (1), the different years for the stations could be covered with an if statement. This method will never be pretty, and I'm sure there are functions to make them easier, but I don't know them.
For (2), no, I did not include station number, but it would simply be another layer of for loops.
You can put all of the information into a single array, but there isn't much difference from a 59000x1 array and a 59000x7 array, especially since you're really only looking at one of those columns. So, the method will work, but its impact will be minimal.
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Data Type Identification についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

