if else statement for tabular data classification
显示 更早的评论
I have data in a table that I would like to classify using an 'if else' statement.
My data is the differences in frequency (total_changes) at intervals on a curve. The data is currently in a 20x10 table and I am now looking to classify these frequency changes into the following categories:
big_rise: >=3000
small_rise: >=500 & <3000
constant: <500 & >-500
small_fall: <=-500 & >-3000
big_fall: >=-3000
From looking online, I have found this suggestion. It has not been working for me and has not given any error messages.
if total_changes<3000
fprintf('large_rise');
elseif total_changes (total_changes>500 & total_changes<3000)
fprintf('small_rise');
elseif total_changes (total_changes<500 & total_changes>-500)
fprintf('constant');
elseif total_changes (total_changes<-500 & total_changes>-3000)
fprintf('small_fall');
else
fprintf('large_fall')
end
I am pretty new to MATLAB so apologies if this is rudimentary stuff, but I would be extremely grateful for some help with this!
If any more information/screenshots are needed, please let me know.
Thanks
采纳的回答
更多回答(1 个)
darova
2020-7-1
0 个投票
Try for loop

2 个评论
RufusS
2020-7-1
darova
2020-7-2
Sorry to misunderstand you. I mean just adding (i), not replacing
for i = 1:length(total_changes)
if total_changes(i)<3000
fprintf('large_rise');
elseif total_changes (total_changes(i)>500 & total_changes(i)<3000)
fprintf('small_rise');
elseif total_changes (total_changes(i)<500 & total_changes(i)>-500)
fprintf('constant');
elseif total_changes (total_changes(i)<-500 & total_changes(i)>-3000)
fprintf('small_fall');
else
fprintf('large_fall')
end
end
类别
在 帮助中心 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!