how to run feature selection in a 3D matrix

조회 수: 2 (최근 30일)
Hugo
Hugo 2022년 2월 22일
답변: Ronit 2024년 8월 23일
Hi,
I have a 3D matrix in MATLAB. I would like to run the function fscmrmr(), in which the column 32 is my reference variable. How can call the function fscmrmr()?. I currently have the following code:
for i=1:1:48
[idx1(i),scores1(i,:,:)] = fscmrmr(Matrix(i,:,:),Matrix(i,:,32));
end
Any suggestions would be really appreciated.
Best regards,

답변 (1개)

Ronit
Ronit 2024년 8월 23일
Hello Hugo,
To perform feature selection using the fscmrmr() function on a 3D matrix in MATLAB, you need to ensure that the dimensions of the matrices you pass to the function are appropriate. The fscmrmr() function is typically used for 2D matrices, where rows represent observations and columns represent features.
In this case, we have a 3D matrix Matrix with dimensions (M, N, 48) and want to use column 32 as the reference variable for feature selection.
% Assuming Matrix is of size (M, N, 48)
numSlices = size(Matrix, 3);
M = size(Matrix, 1);
N = size(Matrix, 2);
idx1 = cell(numSlices, 1);
scores1 = cell(numSlices, 1);
for i = 1:numSlices
% Extract the i-th slice
slice = squeeze(Matrix(:, :, i));
% Ensure that the reference variable is a column vector
referenceVar = slice(:, 32);
% Run feature selection
[idx1{i}, scores1{i}] = fscmrmr(slice, referenceVar);
end
  • Squeeze the Slice to convert the 3D slice into a 2D matrix for each iteration.
  • This code will iterate over each slice of the 3D matrix, perform feature selection using fscmrmr(), and store the results in idx1 and scores1.
Please go through these documentation links for better understanding:
  1. fscmrmr() - https://www.mathworks.com/help/stats/fscmrmr.html
  2. squeeze() - https://www.mathworks.com/help/matlab/ref/squeeze.html
Regards!

카테고리

Help CenterFile Exchange에서 Downloads에 대해 자세히 알아보기

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by