help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Importing columns as a matrix


From: \"Niedermayr, Arthur\"
Subject: Re: Importing columns as a matrix
Date: Sun, 11 Jun 2017 07:44:06 -0400

Hi,
thank you very much for your answer, it was very useful!

I have a further question regarding this special function:
A=dlmread("6-columns.txt"," ",[0 0 22107 5], "emptyvalue" , NA);

If line 22107 looks like this:
2.2 3.3 4.4
My array looks like this:
2.2 3.3 4.4 0.0 0.0 0.0

This functions gives me only NA if the line consists of letters,
eg.
2.2 3.3 4.4 x x x
Then:
2.2 3.3 4.4 NA NA NA

It means notexistent values give 0, letters NA.

Is there a way that i get always "NA" instead of "0.0" ? (Otherwise I have to do some matrix rearrangements which are not as trivial as they seem to be; they are also time consuming if the array is large)

Best regards and thank you in advance!
Arthur Niedermayr



-------- Original Message --------
Subject: Re: Importing columns as a matrix
Local Time: June 2, 2017 1:54 AM
UTC Time: June 1, 2017 11:54 PM
From: address@hidden
To: "Niedermayr, Arthur" <address@hidden>
address@hidden <address@hidden>

On Fri, Jun 2, 2017 at 12:56 AM, "Niedermayr, Arthur"
<address@hidden> wrote:
> Hello everybody,
>
> I basically want to import with GNU Octave a matrix of numbers.
>
> It consists of 132651 values which equals 51x51x51 (later I want to reshape
> my matrix with
> reshape(Matrix,51,51,51))
>
> The problem is the format of my data file that I want to import:
> it consists of 6 columns like the following example shows:
>
> 1.value 2.value 3.value 4.value 5.value 6.value
> ...
> ...
> ...
> 132649.value 132650.value 132651.value no-value no-value no-value
>
> So the last 3 values of my 6 x 22109 array are empty (6x22109-3=132651). If
> they would be ignored everything would be perfect.
>
> My data-import command is the following:
> my_textfile=load ("-ascii", "6-columns.txt");
>
> But due to the fact that 3 values are missing, I get the following error:
> error: load: 6-columns.txt: inconsistent number of columns near line 22109
>
> Is there a simple workaround for that?
> Every help is really appreciated! Thank you in advance!
>
> Best regards
> Arthur Niedermayr
>
>
>
>
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/help-octave
>
The simplest hack is to erase the last line of your data and add it
later manually. You could also use dlmread and read all except the
last row or to insert NA in the missing values.

1. first hack
sed '$ d' 6-columns.txt > 6-columns_new.txt

2. hack
x = dlmread ("6-columns.txt", " ", [0 0 22107 5])

dlmread can also put empty value son those missing ones

x = dlmread ("6-columns.txt", " ", "emptyvalue", NA)

the last row of x will be
132649.value 132650.value 132651.value NA NA NA


reply via email to

[Prev in Thread] Current Thread [Next in Thread]