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
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
wissam abdallah 2018 年 2 月 13 日
hi first i have exported it from my database tables having the fields(stationcode year month day temperatureValue) to excel sheet and then i imported it from from excel to mat lab under the name data.mat
Bob Thompson
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
wissam abdallah 2018 年 2 月 13 日
編集済み: wissam abdallah 2018 年 2 月 13 日
1) hi i tried this for I = 1:length(year) x = months(I); y = temp(months(I)); plot(x,y); clear x y; end
i am getting the error: Error using year (line 22) Please enter D.
2) in fact as a structure for my data: ST_CODE type cell; YEAR type double; MONTH type cell; DAY type double; TEMPERATURE type double;
3) I am looking for a script that can plot the MEAN of TEMPERATURE in twelve MONTHS per YEAR according to a specific ST_CODE. i will be grateful is you can help me accomplish this script
Bob Thompson
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
wissam abdallah 2018 年 2 月 13 日
編集済み: wissam abdallah 2018 年 2 月 13 日
yes all my data tables that are exported from my data base are fragmented into arrays in MATLAB ; i mean: all of ST_CODE ; YEAR ; MONTH ; DAY ; TEMPERATURE are arrays
about the mean you are right, i want to plot for example mean taken from the daily temperature value for each month in a year according to a specific Station for example:
beirut 2010 jan 25.3 * Note* 25.3 is Mean of Temperature for jan in 31 days(temprDay1 + ..+temprDay31/30)
beirut 2010 feb 35.2 --same for feb mean 35.2
beirut 2010 march 36.3 --same for march mean 36.2
and so on..
finaly i would like to plot the mean of temperature for 12 monthes of year 2010 for station beirut
Bob Thompson
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
wissam abdallah 2018 年 2 月 13 日
ahaaaa Ok you are right because when they are in table archive and i exported them to excel they are as organized as follow :
but when i imported them to mat lab all rows are fragmented into arrays as follow:
Bob Thompson
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
wissam abdallah 2018 年 2 月 13 日
hi Mr first i would like to express all my respects for your follow . about the link you have sent i checked it but the page seems to be not available anymore.
about the algorithm you have sent, i think it is difficult to apply it for many reasons: 1. the data that i have exported form the data base and imported to matlab include many stations(7 stations) which are different each other form the period of data collecting for example for stations: beirut available data period spreed form 1963 to 2016 tripoli available data period spreed form 1963 to 2016 Zahleh available data period spreed form 1963 to 2016 Arz available data period spreed form 1950 to 1963 marjeeyoun available data period spreed form 1950 to 1963
2. the algorithm you have sent is missing for the station Code, because i want to plot data also according to a specific ST_CODE such as beirut, tripoli ...
maybe starting form the Arrays that are generated form matlab while i am importing the data ,if i can reconstruct my data by integrating all these arrays into one array that include them overall in the same order that have been in my table excel , such that i can write algorithm to the integrated array in order to plot data based on all my criteria s. do you agree with me about this solution if yes, are there in matlab algorithms(procedure r functions ... ) that satisfied my requirements in this mission? thank you a lot Mr .. and i appreciate again your support Regards
Bob Thompson
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.

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

 採用された回答

Jeff Miller
Jeff Miller 2018 年 2 月 13 日

0 投票

If you convert your data into MATLAB's table format, PlotTbl may be useful (and save you a lot of nested for loops).

1 件のコメント

wissam abdallah
wissam abdallah 2018 年 2 月 15 日
thank you Mr for your help. after checking the link you have sent i typed the following command climTable = table(ST_CODE, YEAR, MONTH, DAY, TMEAN); and now my variables overall have been reconstructed and integrated in the table climTable as they were in the file excel regards

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeData Type Identification についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by