Fixunknowns function resulting logical rows

1 visualización (últimos 30 días)
Randi Pratama
Randi Pratama el 16 de Ag. de 2018
Editada: Randi Pratama el 16 de Ag. de 2018
Hello everyone,
Say Num is matrix with these numbers,
1 2 NaN 3
4 5 NaN NaN
NaN 3 2 3
And if fixunknowns used on Num, it will result like this,
1.0000 2.0000 2.0000 3.0000
1.0000 1.0000 0 1.0000
4.0000 5.0000 4.5000 4.5000
1.0000 1.0000 0 0
2.6667 3.0000 2.0000 3.0000
0 1.0000 1.0000 1.0000
Is there any way to get rid those 1 and 0 (logical) rows? If so please kindly answer this question, or guide me to the documentation if it's available.
Thank you,
Randi

Respuesta aceptada

Stephen23
Stephen23 el 16 de Ag. de 2018
Editada: Stephen23 el 16 de Ag. de 2018
Where M is the output matrix:
new = M(1:2:end,:)
  4 comentarios
Stephen23
Stephen23 el 16 de Ag. de 2018
Editada: Stephen23 el 16 de Ag. de 2018
"Just a little bit curious, how is it works?"
The fixunknowns help clearly describes the output matrix: you only want every second row. This is easy to do with indexing (as my answer shows). Using indexing is one of the most basic MATLAB operations, as shown in the introductory tutorials:
And in more detail here:
The indexing in my answer simply uses the colon operator to generate a row index selecting every second row, starting from the first row, and going until the end row. The colon for the column index means "all columns" of the matrix.
"I've tried a bigger matrix with inf number on it and it doesn't work"
Indexing works for all MATLAB arrays, regardless of their size. I have no idea what code you tried, how you used Inf, or what "it doesn't work" means. If you want help please show the code you tried and explain what you expected.
Randi Pratama
Randi Pratama el 16 de Ag. de 2018
Editada: Randi Pratama el 16 de Ag. de 2018
I see, in my case the logical rows don't show up if there is no NaN or inf in one rows. Since it show up randomly, it will look like this.
-40.4622 -39.6940 -36.3595 -30.4689 -34.1643 -38.0808 -35.5036 -36.0544 -34.6927 -43.5385 -39.1102 -39.6138
-Inf -42.7852 -36.8174 -30.1588 -35.2925 -41.1073 -36.6398 -36.4354 -35.0243 -Inf -35.7836 -39.5963
1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000
-Inf -37.0857 -40.0706 -31.5189 -35.1094 -36.0910 -36.5473 -46.3665 -35.0425 -37.9092 -36.3211 -Inf
1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000
-Inf -36.1978 -37.9558 -30.7696 -35.4735 -36.5567 -36.2683 -39.5703 -35.3162 -36.2137 -38.4406 -Inf
I've tried to replace the inf and NaN number using ~isfinite. Here's my code by the way.
konfirmasi2=input('Jumlah parameter? (>1) '); % Inputing how many times user want the process to be executed
konfirmasi=cell(size(konfirmasi2));
ukuran=cell(1,konfirmasi2);
filetype='*.wav';
for ulang=1:konfirmasi2
fprintf('Silahkan masukkan parameter ke-%d\n',ulang) % Translated to "Please input no. %d parameter(s)"
file = uigetfile(sprintf(filetype),'MultiSelect','on','Pilih suara yang akan digunakan'); % Select (one or multiple) .wav file(s) used to import to workspace
char = ischar(file);
z=cell(size(file));
if isequal(file,0);
clear file;
return;
end
if char==1; % Transforming char file resulting from importing only one file to cell file
file={file};
z=cell(1,1);
end
for k=1:length(file)
y=audioread(file{1,k},[1 2000]); % Low-spec computer
hasil=mfcc1(y);
hasil=hasil';
hasil=hasil(:)';
hasil=hasil';
z{k}=hasil;
ukuran{ulang}=z;
end
konfirmasi{ulang}=input('Simpan sebagai? ','s'); % Saving output as data struct
Data.(konfirmasi{ulang})=z;
fprintf('\n')
end
trainMatrix=cell2mat(cellfun(@(x) cell2mat(x),ukuran,'un',0));
trainMatrix=fixunknowns(trainMatrix);
trainMatrix=trainMatrix(1:2:end,:); % The new code, try
clc
Much appreciated

Iniciar sesión para comentar.

Más respuestas (0)

Productos


Versión

R2013a

Community Treasure Hunt

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

Start Hunting!

Translated by