Date: 18/02/2020 10:46:10
From: mollwollfumble
ID: 1501953
Subject: "Hellp world" blues.

OK, I want to output a 200*200 array of integers in Octave (similar to Matlab) to a text file that Excel can read. When that works I want to reverse it and send a 200*200 array from Excel to Octave via text file.

First attempt – it outputted the whole array to the 200th column.
Second attempt – it outputted the whole array to the first row, instead of \n being used as a newline character it printed \n in every 201th column.
Third attempt try it on a 5*2 array – no output at all other than creating a blank file.
Fourth attempt try to output hello world to file – no output at all other than creating a blank file.

Command for 4th attempt.

fp1=fopen(“/home/david/Pictures/test.txt”,“w+”); # this works to the extent of creating a blank file in the right place
fprintf(fp1,“hello world”);

I’ve tried replacing double with single quotes, replacing w+ with w, adding a third argument in the fprintf statement, leaving off the final semicolon for each line, deleting the file test.txt, closing and reopening fp1.

When I left the ‘fp1’ out of fprintf for the third attempt it printed perfectly to standard output.

WTF. Have I somehow destroyed linux’s ability to write to files or something?

Starting with typing “octave &” from the terminal, what exactly do I have to do?

Reply Quote

Date: 18/02/2020 10:52:44
From: The Rev Dodgson
ID: 1501954
Subject: re: "Hellp world" blues.

I know nothing about Octave, but:

Doesn’t it have an option to save to csv?

A search on Octave to Excel has several links that look like they might be useful.

Reply Quote

Date: 18/02/2020 12:30:04
From: SCIENCE
ID: 1501981
Subject: re: "Hellp world" blues.

mollwollfumble said:


When I left the ‘fp1’ out of fprintf for the third attempt it printed perfectly to standard output.

left it out or changed it to printf ¿

Reply Quote

Date: 18/02/2020 14:18:34
From: mollwollfumble
ID: 1502005
Subject: re: "Hellp world" blues.

SCIENCE said:


mollwollfumble said:

When I left the ‘fp1’ out of fprintf for the third attempt it printed perfectly to standard output.

left it out or changed it to printf ¿

Both, same result with third attempt. fprintf without the fp1 becomes a synonym for printf.
Got too fed up to test it on fourth attempt.

The Rev Dodgson said:


I know nothing about Octave, but:

Doesn’t it have an option to save to csv?

A search on Octave to Excel has several links that look like they might be useful.

If it does, then that would be superb. May be in one of the extra bolt-on packages of octave. Routines dlmwrite(), dlmread(), csvwrite() & csvread() come from, um …

Octave and presumably matlab has a format that is peculiarly between that of Fortran and C. The array style starting a(1,1) is from Fortran and the IO with fprintf is from C. In Fortran it is an absolute doddle to read and write .cvs files, but in C it’s more of a pain.

Reply Quote

Date: 18/02/2020 14:57:37
From: mollwollfumble
ID: 1502045
Subject: re: "Hellp world" blues.

mollwollfumble said:


SCIENCE said:

mollwollfumble said:

When I left the ‘fp1’ out of fprintf for the third attempt it printed perfectly to standard output.

left it out or changed it to printf ¿

Both, same result with third attempt. fprintf without the fp1 becomes a synonym for printf.
Got too fed up to test it on fourth attempt.

The Rev Dodgson said:


I know nothing about Octave, but:

Doesn’t it have an option to save to csv?

A search on Octave to Excel has several links that look like they might be useful.

If it does, then that would be superb. May be in one of the extra bolt-on packages of octave. Routines dlmwrite(), dlmread(), csvwrite() & csvread() come from, um …

Octave and presumably matlab has a format that is peculiarly between that of Fortran and C. The array style starting a(1,1) is from Fortran and the IO with fprintf is from C. In Fortran it is an absolute doddle to read and write .cvs files, but in C it’s more of a pain.

> Doesn’t it have an option to save to csv?

Good try but no cigar. Sorry, I moved the goalposts. Was trying:

img=imread(“/home/david/Pictures/mundo.png”) # img has dimensions 200*200*3, the 3 comes from rgb.
csvwrite(“/home/david/Pictures/mundo.csv”,img);

fails with “error: transpose not defined for N-D objects” That makes sense because it’s trying to write row first when it’s stored as column first.

Reply Quote

Date: 19/02/2020 04:08:18
From: mollwollfumble
ID: 1502270
Subject: re: "Hellp world" blues.

Thanks to Rev D, this works.

img=imread(“/home/david/Pictures/mundo.png”);
img1=img

Reply Quote

Date: 19/02/2020 09:06:40
From: The Rev Dodgson
ID: 1502287
Subject: re: "Hellp world" blues.

mollwollfumble said:


Thanks to Rev D, this works.

img=imread(“/home/david/Pictures/mundo.png”);
img1=img

Not sure how I helped, but glad I did. :)

Reply Quote

Date: 19/02/2020 18:43:12
From: mollwollfumble
ID: 1502611
Subject: re: "Hellp world" blues.

The Rev Dodgson said:

Not sure how I helped, but glad I did. :)

You made me find csvwrite.

Reply Quote

Date: 21/02/2020 19:56:33
From: mollwollfumble
ID: 1503499
Subject: re: "Hellp world" blues.

mollwollfumble said:


Thanks to Rev D, this works.

img=imread(“/home/david/Pictures/mundo.png”);
img1=img(1:200,1:200,1);
img2=img(1:200,1:200,2);
img3=img(1:200,1:200,3);
dlmwrite(“/home/david/Pictures/mundo.csv”,img1);
dlmwrite(“/home/david/Pictures/mundo.csv”,img2,“append”);
dlmwrite(“/home/david/Pictures/mundo.csv”,img3,“append”);

Reversing it doesn’t work, right shape wrong colours

>> newimg=dlmread(“/home/david/Pictures/mundo.csv”);
>> newimg1=newimg(1:200,1:200);
>> newimg2=newimg(201:400,1:200);
>> newimg3=newimg(401:600,1:200);
>> newimg0(1:200,1:200,1)=newimg1;
>> newimg0(1:200,1:200,2)=newimg2;
>> newimg0(1:200,1:200,3)=newimg3;
>> image(newimg0);

Oops, didn’t display properly last time. Also, now I can use resize() to replace the manual split into rgb components, and I can use uint8() to get gif and csv files to read correctly as images.

Reply Quote

Date: 23/02/2020 18:01:22
From: SCIENCE
ID: 1504484
Subject: re: "Hellp world" blues.

dv said:


Ah, that logo I was asking about turned out to be for Helloworld.

Reply Quote