MATLAB: How to perform individual operation on a Column of data from excel file

importing excel dataxlsread

I am intended to perform a separate operation (adding/subtracting some values) on Positive and Negative value from an Excel dataset using Matlab. To read the column I use the following code
num = xlsread('testdata.xls', 'B:B');
it reads fine and when I ask 'num' it shows the data. However, the data are having positive and negative values. I want to add some values to negative dataset and substruct from the positive dataset by keeping their position alike so that I can reconstruct a graph having exactly the same pattern. I have made two attempts:
1. Using logical indexing I can separate the positive and negative values and then perform the operation but can't combine them in the same order, something like following
idx = num<0;
neg = num(idx)+ 1.0e-08
pos = num(~idx)- 1.0e-08
2. If-else also not working at all:
if (num<0)
num = num +1
elseif(num>0)
num = num +2
end
Any help, please?

Best Answer

idx = num<0;
num(idx) = num(idx)+ 1.0e-08
num(~idx)= num(~idx)- 1.0e-08
Related Question