Simple FOR loop question
显示 更早的评论
I have a column vector (GUI_NEWABS) which contains all positive numbers. I need to change some of the values within it to negative (i.e. *-1) based on whether the associated value in another coloumn vector (GUI_DATA) is positive or negative (GUI_NEWABS is a result of transformations performed on GUI_DATA). Basically I want the sign of the number in each row of GUI_NEWABS to match the sign of the number in the same row of GUI_DATA.
I've tried to use an IF function (i.e. if (sign(GUI_DATA) == 1) but this doesn't work, presumably because the IF function is trying to calculate whether the entire column = 1. Therefore I presumably I need to use a FOR loop to scroll through each value in GUI_DATA. I've tried a couple of different syntax, including the following..
for GUI_DATA
GUI_NEWABS = GUI_NEWABS *(sign(GUI_DATA));
end
however I keep getting an error on the 'for GUI_DATA' line saying that the statement is incomplete/incorrect. Given that I want to scroll through ALL rows of this vector what do I need to put in this line to get it to work?
Thanks Rob
采纳的回答
更多回答(1 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!