If-statement = true then replace column with specfic value - How to?
4 次查看(过去 30 天)
显示 更早的评论
Hey
I'm trying to replace a whole column with a specific value if the number already appears in the column
Any suggestions?
My current output is the same as the input except for the one space where -3 appears it replaces it with 0 for some reason
m = size(input, 1);
n = size(input, 2);
for i = 1:n
for j = 1:m
if (input(i,j) == -3)
inputTemp(i,:) = -3;
i = i + 1;
else
inputTemp(i,j)= input(i,j);
end
end
end
2 个评论
采纳的回答
KALYAN ACHARJYA
2019-6-25
编辑:KALYAN ACHARJYA
2019-6-25
[m n]=size(input);
for i=1:m
for j=1:n
if input(i,j)==-3
inputTemp(i,:)=-3;
end
end
end
Same code can be implemeneted without loop-Recomended
inputTemp?? Please note you are not going to "replace column with specfic value"
As per the code, when any element =-3, then only respective row elements (definitely all columns) are forced to -3.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!