0

still fairly new to matlab, picked up this data analysis code from someone and I had to add in new functions.

for one function I'm calculating the average of every 3 entries in one column and print the result on another column. so it would be something like this

1 -1
3 -1
5 =(1+3+5)/3
7 -1
1 -1
1 =(7+1+1)/3
4 -1

what I wish to do is to print a blank in the cells that have -1. my first thought was to just assign string values to my results instead of ints. this didn't work because I think there is a line of code in there somewhere that converts everything to ints.

another possible solution is just to reopen the file and loop through all cells replacing any -1's with blank strings, though I'm not sure how to do this, and it's inefficient.

as last resort, I guess I can always tell the user of this xls sheet to use the find/replace function in excel before processing it.

edit: partial code of the save part:

data = [data.time, data.avg_time'];
data2 = num2cell(data);
data3 = {'t', 'avg t'};
data = [data3; data2];
xlswrite([filename, '.xls'], data);
4

1 回答 1

1

I misunderstood your question (i thought of replacing NaN's with -1, thanks Amro).

You can use this:

A(A(:,2)==-1,2)=NaN

where A is the matrix you created first.

Hope it helps you :)

于 2012-07-26T00:06:33.917 回答