changing data based on values
显示 更早的评论
I have a very long string of data, and I want to change each value based on if it is in between certain values in another set of data.
for example, my string of data is 1, 5, 5, 3, 6, 8. I want to change those numbers to 1 if they are between 1 and 3, 2 if they are between 4 and 6, and 3 if they are between 7 and 9. The result should be 1, 2, 2, 1, 2, 3.
In my code, I have the very long string of data that I want to change as X, the range data as Y, and what I want to change it to as Z. The code I came up with (which doesn't work) is:
X(Y(1,:)<X(:,1)<Y(2,:),1) = Z(1,:);
X(Y(2,:)<X(:,1)<Y(3,:),1) = Z(2,:);
X(Y(3,:)<X(:,1)<Y(4,:),1) = Z(3,:);
Etc.
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!