Help for matrix in matlab

7 Ansichten (letzte 30 Tage)
Amy Topaz
Amy Topaz am 14 Apr. 2022
Kommentiert: the cyclist am 3 Jun. 2023
How to convert a 20*20 matrix into 20*1 matrix in matlab
  1 Kommentar
Riccardo Scorretti
Riccardo Scorretti am 14 Apr. 2022
Hi Amy, the problem as formulated is ill posed. What do you mean exactly by "converting a matrix"? Please, provide a simple example of what you want to do.

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Kautuk Raj
Kautuk Raj am 2 Jun. 2023
Bearbeitet: Kautuk Raj am 3 Jun. 2023
I am assuming that you wish to get a 400x1 matrix, instead of a 20x1 matrix, the latter being not possible without dropping elements. To convert a 20x20 matrix into a 400x1 matrix in MATLAB, we can use the reshape function. To cite an example:
% Define a 20x20 matrix
A = rand(20);
% Reshape the matrix into a 400x1 column vector
A_col = reshape(A, [], 1);
In this code, we first define a 20x20 matrix A using the rand function to generate random values. We then use the reshape function to reshape the matrix into a 400x1 column vector A_col.
More details about the reshape function can be found here.
  1 Kommentar
the cyclist
the cyclist am 2 Jun. 2023
The result is not a 20x1 column vector:
% Define a 20x20 matrix
A = rand(20);
% Reshape the matrix into a 20x1 column vector
A_col = reshape(A, [], 1);
size(A_col)
ans = 1×2
400 1
What the OP asked for is not possible without further information about what they mean.

Melden Sie sich an, um zu kommentieren.


Walter Roberson
Walter Roberson am 3 Jun. 2023
prod(M, 2)
sum(M, 2)
min(M, 2)
max(M, 2)
any(M, 2)
all(M, 2)
std(M, [], 2)

amongst others

  1 Kommentar
the cyclist
the cyclist am 3 Jun. 2023
How silly can we get, within the bounds of the request?
M(randperm(400,20))'; % :-)

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by