CSVread empty cells non zero

13 visualizaciones (últimos 30 días)
Hayley Sanders
Hayley Sanders el 19 de Mzo. de 2019
Respondida: Raghunandan V el 19 de Mzo. de 2019
I'm trying to change the default empty cell input for Matlab.
I need to read a csv file and output an array using csvread. I suspect that after it reads and puts it into the array it's already zero so can't read as empty?
function [A] =createanarray(filename, linestoskip)
A=csvread(filename,linestoskip); %read the file and skip the input number of lines
if A(isempty(A))=-999
A(A<0)= NaN; %make no value NaN
A; %output A array
end
Many thanks!
  2 comentarios
Jan
Jan el 19 de Mzo. de 2019
Editada: Jan el 19 de Mzo. de 2019
Today I've formatted your code to increase the readability. You can do this by your own in the future.
I cannot guess the purpose of: A(isempty(A))=-999 . This is not a comparison, but an assignment. See the difference between = and == . The statement "A;" is useless also.
csvread does not import empty elements. Please post what your inputs are and what you want as output.
Hayley Sanders
Hayley Sanders el 19 de Mzo. de 2019
So for example the file i want to import is an excel csv that is:
2 3 3 4 0
1 2 3 4
0 0 2 3 1
With a blank cell. On assignment of array A with
A=csvread('filename')
it changes the blank cell to a zero value. I want to change this to NaN entry.

Iniciar sesión para comentar.

Respuestas (1)

Raghunandan V
Raghunandan V el 19 de Mzo. de 2019
Hi, The answer is simple. You try with xlsread
[A, B, C ] = xlsread('Data.xlxs');
Here A gives all the numbers of the matrix.
So if there is a cell with no numbers then it will return NaN. Even if there is a string or emptry cell it still returns NaN.
Try it!

Categorías

Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by