Function to fill an array given conditions.
古いコメントを表示
Hi All,
I am trying to write a function to fill an array given conditions. basiclly the user inputs two variables a max and min and given these
values it creates two new row vectors, ph and date, which is a subset of an orignal vector.
My code is given below -
function [datenew,phnew] = subsetdata(date, ph, pressure, min, max)
%create empty array
datenew=cell(1,5000);
phnew=cell(1,5000);
%loop through each point
for i=1:size(pressure)
%check condition
if (pressure(i,:)>=min & pressure(i,:)<max)
%fill array if condition met
datenew{i}=date(i);
phnew{i}=ph(i);
end
end
end
2 件のコメント
Andrew Czeizler
2019 年 3 月 13 日
編集済み: Andrew Czeizler
2019 年 3 月 13 日
Adam
2019 年 3 月 13 日
What is your question?
Also, never use min and max as variable names. These are function names in Matlab and by creating variables with those names you hide the respective functions and make them inaccessible to use.
採用された回答
その他の回答 (1 件)
Andrew Czeizler
2019 年 3 月 13 日
0 投票
3 件のコメント
Adam
2019 年 3 月 13 日
See my reply above.
Andrew Czeizler
2019 年 3 月 13 日
Adam
2019 年 3 月 13 日
If you want to retain the positions within the array then yes. You could use -1 if all true data should be positive, but NaN is more logical.
カテゴリ
ヘルプ センター および File Exchange で Dates and Time についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!