필터 지우기
필터 지우기

conditional data selection and saving back to file

조회 수: 1 (최근 30일)
Sudhir Rai
Sudhir Rai 2021년 3월 11일
댓글: Mathieu NOE 2021년 3월 12일
I have data matrix x= row [1 :2:100] and y =row[1:2:100] same number of elements in x and y.
i want to choose data with following conditions,
for x<20 select data at interval of 5 which is [1; 6; 11; 17]
for 20<x<50 select data at interval of 10 which is [20; 30; 40; 50]
for 50<x<100 data selection at interval of 8 ......
same for y and then I have to plot x vs y
how can I easily do it for larger set of data for x and y and save it later in .txt or excel file.
Thank you.

채택된 답변

Mathieu NOE
Mathieu NOE 2021년 3월 11일
hello
this is my suggestion
NB the input data I have changed the delta to 1 so that it works for the tasks you asked
clc
clearvars
x= (1:100)';
y = sin(0.25*x)+0.1*x;
% i want to choose data with following conditions,
% for x<20 select data at interval of 5 which is [1; 6; 11; 17]
% for 20<x<50 select data at interval of 10 which is [20; 30; 40; 50]
% for 50<x<100 data selection at interval of 8 ......
% same for y and then I have to plot x vs y
% how can I easily do it for larger set of data for x and y and save it later in .txt or excel file.
% below vector have length equal to number of cases stated above
% you easily expand the number of conditions without doing manual tweaks
lim_low = [1 20 50]; % define here the lower limits of range
lim_up = [20 50 100]; % define here the uper limits of range
steps = [5 10 8]; % define here the steps
%%% main loop %%
ind = [];
for ci = 1:numel(steps)
ind = [ind (lim_low(ci):steps(ci):lim_up(ci))]; %#ok<*AGROW>
end
ind = unique(ind); % remove duplicates if any
xx = x(ind);
yy = y(ind);
plot(x,y,'b',xx,yy,'dr')
A = [xx(:) yy(:)];
writematrix(A,'out_file.txt');
  댓글 수: 2
Sudhir Rai
Sudhir Rai 2021년 3월 12일
Thank you. It worked for my condition.
But is there a way to select data at certain interval without giving any limit (upper ..lower)
I am asking this because i want to use it for analyzing huge random data (millions).
Mathieu NOE
Mathieu NOE 2021년 3월 12일
I am not sure to understand - how would you define then the intervals and steps ?
maybe I didn't understand in the first place the purpose of that code

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by