Converting Certain Data from Numeric Matrix to Text

  • Follow


Hi all,

Below is an example of the set of XYZ data I am working with:

XYZdata = [ 1 1 0.4
                  1 2 0.2
                  1 3 0
                  2 1 0
                  2 2 0.8
                  2 3 0.7 ] 

I would like to find all Z values that are zero and replace the zero with the term 'No Data'. What is the best way to do this? I have been tinkering with cell arrays to no avail so far. I am working on some code to write this data to a text file, however the machine that I need to export this data to requires the zeroes to be shown as 'No Data' so it won't plot these points.

Thanks!

Andrew
0
Reply Andrew 6/3/2010 7:29:04 PM

Andrew McDonald wrote:

> Below is an example of the set of XYZ data I am working with:
> 
> XYZdata = [ 1 1 0.4
>                  1 2 0.2
>                  1 3 0
>                  2 1 0
>                  2 2 0.8
>                  2 3 0.7 ]
> I would like to find all Z values that are zero and replace the zero 
> with the term 'No Data'. What is the best way to do this? I have been 
> tinkering with cell arrays to no avail so far. I am working on some code 
> to write this data to a text file, however the machine that I need to 
> export this data to requires the zeroes to be shown as 'No Data' so it 
> won't plot these points.

T = str2num(' %7g', XYZdata);
T(find(XYZData(:,3) == 0), end-6:end) = 'No Data';

Easier than I thought...

0
Reply Walter 6/3/2010 7:41:33 PM


I may be missing something, but I'm getting an error with the solution you posted, Walter. Not really sure what I'm doing wrong here, but I get an error with your first line due to too many input arguments in the str2num function, and even when I remove the ' %7g' input argument from the str2num function call I still get an error because my XYZdata matrix is a numerical matrix, not a string. I'm sorry that I didn't communicate that very well in my first post.

The matrix I am working with is a numerical matrix with three columns of data (x, y, and z). I need to write this data to a text file, but the caveat is that for every Z value that is equal to 0 I need to write to the file as 'No Data'.

How much more complicated does this become? As I mentioned before, I'm very novice at using cell arrays, but it seems to me that I will need to convert my numerical matrix to a cell array so I can maintain my integer data in columns 1 and 2 (x and y data) and have a mixture of double data and string data in column 3 (z data).

I really appreciate the help.
0
Reply Andrew 6/4/2010 12:49:06 PM

2 Replies
365 Views

(page loaded in 0.042 seconds)

Similiar Articles:













7/25/2012 10:39:53 PM


Reply: