segregate table in mat lab

조회 수: 1 (최근 30일)
wissam abdallah
wissam abdallah 2018년 2월 15일
댓글: wissam abdallah 2018년 2월 19일
hi I have the following table in mat lab.
I want to create a procedure or function in mat lab so as I can loop through the mention table and segregate it into two tables:
First one contains all information for the station LR as shown below
Secon one contain all information for the staionn LZ as shown below
Anyone can help me to do this algorithm will be appreciate
Regards.
  댓글 수: 6
Steven Lord
Steven Lord 2018년 2월 16일
Once you've subdivided your data based on ST_CODE, what types of operations do you want to perform on the data? Consider using some of the grouped calculations functionality shown on this documentation page.
I also see you have date data (YEAR, MONTH, DAY) in your table. If you have access to release R2016b you might want to investigate storing your data in a timetable (introduced in R2016b) instead if you want to perform some date-based analysis on your data.
wissam abdallah
wissam abdallah 2018년 2월 16일
after subdivided the global matrix i would like to:
1-plot the mean of TMIN per monthes(12 monthes)in year 2010 and 2011 for station LR40102.
as well as
2- plot the mean of TMIN per monthes(12 monthes)in year 2010 and 2011 for station LZ40103.
3- i would like to separate the Matrix rows of my data into two matrix's one for LR40102 and the other for LZ40103. and thus i could make all the calculation on the appropriate matrix separately.
Regards.

댓글을 달려면 로그인하십시오.

채택된 답변

Peter Perkins
Peter Perkins 2018년 2월 17일
Simple solution posted in reply to your identical double post.

추가 답변 (1개)

Pawel Jastrzebski
Pawel Jastrzebski 2018년 2월 16일
편집: Pawel Jastrzebski 2018년 2월 16일
Consider the following code:
% table
t = array2table(rand(10,2))
rowNames = {'a1' 'a2' 'a3' 'a4' 'a5' 'b1' 'b2' 'b3' 'b4' 'b5'}
t.Properties.RowNames = rowNames
% 1st WAY
% if you know where your elements are in the table
% i.e. the split is 50/50 then
splitVector_1stHalf = 1:0.5*size(t,1)
splitVector_2stHalf = 0.5*size(t,1)+1:size(t,1)
t1 = t(splitVector_1stHalf,:)
t2 = t(splitVector_2stHalf,:)
clear t;
%---------------------------------------------------
% table
t = array2table(rand(10,2))
rowNames = {'a1' 'b2' 'b3' 'a4' 'a5' 'b1' 'a2' 'a3' 'b4' 'b5'}
t.Properties.RowNames = rowNames
% 2nd way
% get the split by the row name
% get the row names
names = t.Properties.RowNames
compare = strfind(names,'a');
logicalVecotor = logical(zeros(1,size(compare,1)));
for i=1:size(compare,1)
logicalVecotor(i) = isempty(compare{i});
end
logicalVecotor
t1new = t(logicalVecotor,:)
t2new = t(~logicalVecotor,:)
  댓글 수: 3
Pawel Jastrzebski
Pawel Jastrzebski 2018년 2월 19일
  1. It would have been so much easier if to understand the problem if you had embedded the code as code, not as a plain text.
  2. You're using readtable to import the data from the excel spreadsheet to matlab - you import is as a TABLE already - don't use array2mat after that. I did it in my example as I needed to quickly create some exemplary table to work with.
  3. In my example I make have assigned the row names to the table and made a division using those names. If you want to make sure this method works, you need to import your data with the first column being treated as the 'row names'.
  4. If you want to keep your first column as a variable rather than 'row names' - then I believe Peter Perkins has provided the way to do it in your other thread.
  5. General remark, if someone provides a workable example as a solution to your problem - first thing you should do is to make sure you understand every single function used. That means reading the definitions up in the documentation.
wissam abdallah
wissam abdallah 2018년 2월 19일
Ok . Mr thank you for your support. Regards

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by