how to put vectors with different size in one matrix and how to suppress the NAN in this matrix

1 view (last 30 days)
Hello, I have two difficulties with my script, the first is that I have vectors with different size et I want to create a matrix and then to fill with my different vectors but I think I do the wrong thing with Mat=[ 10000,11] . The other thing is that I want clearly to suppress all NAN in my matrix only in my vector TR_NAN. Have you an idea please?
filename = 'C:\Users\williot\Dropbox\UQTR 2013 - 2015\E-Prime\exp 2 ÉNPQ\eye-tracking\données brutes 30 aspirants\test_matlab.xlsx';
%'E:\exp 2 ÉNPQ bis\Cueing + TRV\test_script_matlab.xlsx';
[num,txt,raw] = xlsread(filename);
%--création matrice Mat---------------------------------------------
Sujets = num(:,1);
Essais = num(:,30);%82
TR_NAN = num(:,115);%104
TR_acc = num(:,112);%101
validite = txt(:,147);%138
contenu = txt(:,112);%101
question = txt(:,143);%134
procedure = txt(:,137);%68
bloc = txt(:,95);%84
running = txt(:,92);%137
Data_OK = [];
% Mat = [1009 138]
Mat=[]
Mat=[10000,11]
Mat = [Sujets Essais TR_NAN TR_acc Data_OK validite ...
contenu question procedure bloc running];
Mat(isnan(Mat(:,3)),:) = [];
%===================================================================
%--exclusion des TR à + ou - 2ET------------------------------------
for suj = 1 :length (Sujets);
Moy_TR = mean (TR_NAN);
ET_TR = std(TR_NAN);
Data_OK = TR_NAN((TR_NAN>Moy_TR-2*ET_TR) & (TR_NAN>Moy_TR+2*ET_TR));
end
%--CONSTRUCTION D'UN FICHIER DE SORTIE-------------------------
%Création de la Matrice finale------------------------------------------------
Mat_out = [Sujets Essais TR_NAN TR_acc Data_OK validite ...
contenu question procedure bloc running];
%--nom fichier------avec excel titre col---------------------
path_and_name_file='PREP_extremes.txt';
%--ouverture fichier
fid=fopen (path_and_name_file,'wt');
%titre colonne-----------------------------------------------
fprintf(fid,'Sujets;Essais;TR_NAN;TR_acc;Data_OK;validite;contenu; ...
question;procedure;bloc;running');
fprintf(fid,'\n');
%écriture
for n=1:length(Mat_out);
fprintf(fid,'%d;%d;%d;%d;%d;%s;%s;%s;%s;%s;%s',Mat_out(n,:));
%1.4f;%1.4f;%1.4f;%1.4f;%1.4f;%1.4f;%1.4f;%1.4f;',Mat_out(n,:));
fprintf(fid,'\n');
end
fclose(fid);

Accepted Answer

Alexandre Williot
Alexandre Williot on 15 Jul 2015
Edited: Alexandre Williot on 15 Jul 2015
Thank you, here what I needed,
Essais =[];
Essais = num(:,93);
Essais(isnan(Essais))=0;
Pos_OK=find(Essais ~= 0);
Pos_OK1=find(Essais == 0);
num=num(Pos_OK,:);
txt= txt(Pos_OK,:);
raw= raw(Pos_OK,:);
Essais = num(:,93);

More Answers (1)

dpb
dpb on 20 May 2015
Matlab can only treat "ragged" arrays as a cell array. Use the "curlies" ( {} ) to place an array in a cell array location.
for ix=1:N
C(ix)={a_vector};
end
C will be a cell array of length N arranged as a row vector by default.
I don't follow the question regarding the NaN, sorry.

Categories

Find more on Characters and Strings in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!