Borrar filtros
Borrar filtros

how to view changed matrix

1 visualización (últimos 30 días)
Chandini Govind
Chandini Govind el 3 de Oct. de 2019
Comentada: Deepak Kumar el 9 de Oct. de 2019
hi,
i have attached a code below
clc
clear
[~,~,A]=xlsread('duplicateset1.xls');
%A(isnan(A))=-1;
cellfun(@isnan,A,'UniformOutput',false)%to remove NaN from array
[m,n]=size(A);
B=A;
%change Y/N to 0/1
for i=1:n
if isequal(A{i},'Y')||isequal(A{i},'M')
B(:,i)=1;
elseif isequal(A{i},'N')||isequal(A{i},'F')
B(:,i)=0;
elseif isequal(A{i},'U')||isequal(A{i},'H')
B(:,i)=2;
elseif isequal(A{i},'C')||isequal(A{i},'D')||isequal(A{i},'L')
B(:,i)=-1;
end
end
B(1:10,3)
i want the B matix to be of 1's and 0's instead of yes and no, but what i get is the intial matrix. the other chararcter represent male/female/high/low etc
  6 comentarios
Chandini Govind
Chandini Govind el 6 de Oct. de 2019
ok,i have uploaded the input file
Deepak Kumar
Deepak Kumar el 9 de Oct. de 2019
I'm assuming that you are trying to read decisionattri.xlsx file.
You are not capturing the values returned by cellfun in a variable (e.g. z=cellfun(@isnan,A,'UniformOutput',false)). So, the values returned by cellfun is lost and A remains unaffected and retains it's original values. That is why you are getting the original values of A. Moreover, please go through the documentation of isnan command (https://www.mathworks.com/help/matlab/ref/isnan.html ) to understand it's usage.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by