how to write for and while loop for my excel data.?? can any one help me..

조회 수: 9 (최근 30일)
J G RAO
J G RAO 2017년 3월 8일
댓글: Voss 2024년 11월 13일 17:49
i have daily data of 36 years in 4 columns manner like: 1/1/1950 1/2/1950 1/3/1950..........29/12/200 30/12/2000 31/12/2000 (days in order, months in order, years in order) in that case, i need 4 months data in each year. for example: june, july, august, september months in each year
how can pick that particular data and place it side help me please..

답변 (1개)

ag
ag 2024년 11월 13일 16:41
Hi J,
To extract data for specific months (June, July, August, and September) from your dataset, you can utilise the "ismember" MATLAB function.
The below code snippet demonstrates how to do that:
% Assuming 'data' is a matrix where each row corresponds
% to a day and the columns are [day, month, year, value]
% Define the months of interest (June, July, August, September)
monthsOfInterest = [6, 7, 8, 9];
% Extract rows where the month is one of the months of interest
selectedData = data(ismember(data(:, 2), monthsOfInterest));
For more details, please refer to the following MathWorks documentation: ismember - https://www.mathworks.com/help/matlab/ref/double.ismember.html
Hope this helps!
  댓글 수: 1
Voss
Voss 2024년 11월 13일 17:49
data = randi(9,5,4)
data = 5×4
4 7 1 9 9 3 2 7 2 6 5 1 5 5 2 6 6 8 2 5
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
monthsOfInterest = [6, 7, 8, 9];
% Extract *elements of first column* of data where second column is in [6,7,8,9]
selectedData = data(ismember(data(:,2),monthsOfInterest))
selectedData = 3×1
4 2 6
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
% Extract *rows* of data where second column is in [6,7,8,9]
selectedData = data(ismember(data(:,2),monthsOfInterest),:)
selectedData = 3×4
4 7 1 9 2 6 5 1 6 8 2 5
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by