Prev: header in matrix
Next: batch mode
From: Stefan Heinen on 4 May 2010 06:45 Hey, I'm exporting a matrix with dlmwrite to txt. Now I'm trying to set a header on top of it.. something like the example here: text = [average, std, cv, min, max] data=[ 10, 5, 3, 1, 10; 10, 5, 3, 1, 10; 10, 5, 3, 1, 10; 10, 5, 3, 1, 10;] the output should look like: output = [average std cv min max; 10 5 3 1 10; 10 5 3 1 10; 10 5 3 1 10; 10 5 3 1 10;] anyone any segestions? Best regards, Stefan
From: ImageAnalyst on 4 May 2010 08:36 You'll need a cell array for that because you're mixing numbers and character strings in the same variable. textHeader = {'average', 'std', 'cv', 'min', 'max'} data=[ 10, 5, 3, 1, 10; ... 10, 5, 3, 1, 10; ... 10, 5, 3, 1, 10; ... 10, 5, 3, 1, 10;] output = {textHeader; data} for k = 1:2 output{k} % Display it to command window. end
From: Stefan Heinen on 4 May 2010 11:35 Thx, I findout that I could use { } these, but I still can't save the output with dlmwrite. I like to export a matrix with a header to a .txt file. Something like: dlmwrite('test.txt', output, '\t') still gives: The input cell array cannot be converted to a matrix. mageAnalyst <imageanalyst(a)mailinator.com> wrote in message <9ad747b8-be0f-4167-8668-18d98900c746(a)o14g2000yqb.googlegroups.com>... > You'll need a cell array for that because you're mixing numbers and > character strings in the same variable. > > textHeader = {'average', 'std', 'cv', 'min', 'max'} > data=[ 10, 5, 3, 1, 10; ... > 10, 5, 3, 1, 10; ... > 10, 5, 3, 1, 10; ... > 10, 5, 3, 1, 10;] > > output = {textHeader; data} > for k = 1:2 > output{k} % Display it to command window. > end
From: ImageAnalyst on 4 May 2010 11:38 Why don't you just write it yourself with fopen(), fprintf() and fclose()? It's really quick and easy. See the examples in those functions. They will give you more flexibility in what you write out and how you write it than dlmwrite, and they're almost as easy to use.
From: Walter Roberson on 4 May 2010 12:06
Stefan Heinen wrote: > I'm exporting a matrix with dlmwrite to txt. Now I'm trying to set a > header on top of it.. something like the example here: > > text = [average, std, cv, min, max] > data=[ 10, 5, 3, 1, 10; > 10, 5, 3, 1, 10; > 10, 5, 3, 1, 10; > 10, 5, 3, 1, 10;] > > the output should look like: > > output = [average std cv min max; > 10 5 3 1 10; > 10 5 3 1 10; > 10 5 3 1 10; > 10 5 3 1 10;] Someone answered showing how to do this to console output, but unfortunately that will not directly help you with dlmwrite. In _practice_ it is possible to use dlmwrite() to produce a mix of text and numbers, but the official dlmwrite documentation indicates that it is not possible. When I say that in practice it can be done, I don't mean that it is easy to do; the effort involved is more than the official solution that Mathworks gives, http://www.mathworks.com/access/helpdesk/help/techdoc/import_export/f5-15544.html#br2ypq2-1 |