how to remove columns from a 3D array, considering user input

3 ビュー (過去 30 日間)
Hugo
Hugo 2022 年 2 月 25 日
編集済み: Jan 2022 年 2 月 25 日
Hello,
I have a 3D matrix A, with dimensions 50*1000*30. I would like to remove some columns of the 30 I have (3rd dimension). The columns that I would like to have removed should be defined by user input, separated by commas. An example of an acceptable input is 1,5,7,9
for the removal of the columns 1, 5, 7 and 9 of all of the 50 tables. I know the input can be coded in something like this:
columns= input('Please write the number of the columns to be removed, separated by commas')
However, I don't know how I can obtain a new matrix, let's call it B, with the columns stated as input (variable columns) removed.
Any suggestions on how to do this?
I thank you in advance,
Best regards,

採用された回答

Jan
Jan 2022 年 2 月 25 日
編集済み: Jan 2022 年 2 月 25 日
Either use square brackets for the input:
b = input('Indices enclosed in square brackets: ');
% Type in: [1,5,7]
Or input a string and convert it manually:
s = input('Indices, comma separated: ', 's');
s = strrep(s, ',', ' ');
b = sscanf(s, '%d');
% b = [1,5,7]
Then:
A = rand(50, 1000, 30);
A(:, :, b) = [];
% Or do you mean the 1st dimension?
% A(b, :, :) = [];

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by