specify size output

Hi I (with lots of help) have written the following code:
In = dlmread(FileName);
[unDates,trash,IDX] = unique(In(:,1:5),'rows');
Out = [unDates zeros(size(unDates,1),1)];
for d = 1:size(unDates,1)
Out(d,end) = mean(In(IDX == d,end));
end
dlmwrite ('IonOut.csv',Out,'-append','precision','%0.10g','delimiter',',');
end
It does its job of finding unique values column 5 of a csv file that looks like this:
2002,1,1 ,13, 731217, 1119.566899634552 , 8.11440000
however the output file leaves off the last column, I cant see what I have done wrong, can anyone help?
Patrick

 採用された回答

Jan
Jan 2011 年 3 月 16 日

1 投票

Does "Out" contain the wanted values? Or do you want to consider the last two columns of the input? Please check this by "disp(Out)".
INSERTED: Code to consider the 6th column also:
[unDates,trash,IDX] = unique(In(:,1:5), 'rows');
siz = size(unDates);
Out = [unDates, zeros(siz(1), 2)];
for d = 1:siz(1)
Out(d, 6:7) = mean(In(IDX == d, 6:7), 1);
end
Are you sure, that you want to append the calculated data to the file?
INSERTED: If you do not want to append the values to the file, omit the -append flag.
dlmwrite('IonOut.csv', Out, 'precision','%0.10g', 'delimiter', ',');

4 件のコメント

Patrick
Patrick 2011 年 3 月 16 日
Hi Jan
No Out does not
Not sure I want to append either. the intention is to create a file that gives the average values of column6 and average of column 7 for each date.
Thanks
Patrick
Oleg Komarov
Oleg Komarov 2011 年 3 月 16 日
use accumarray then
Patrick
Patrick 2011 年 3 月 16 日
Hi Oleg,
thanks. have looked into accumarray now and I dont think it wil work as I am looking for a mean of each date, rather than a sum
Oleg Komarov
Oleg Komarov 2011 年 3 月 16 日
You can specify any function which returns a scalar when applied to a vector:
accumarray(subs,vals,[],@mean)

サインインしてコメントする。

その他の回答 (1 件)

Patrick
Patrick 2011 年 3 月 16 日

0 投票

Thank you gentlemen,
As you can no doubt see I'm new to MATLAB, Patrick

カテゴリ

質問済み:

2011 年 3 月 16 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by