How we can do the matrix and vector in vector form?

clc;
clear all ;
close all;
format long g;
%% developing the function for the reverse in the vector concate and reverse it
A = [1;2;3]
B = [4 5 6;8 9 11]
[numRows,numCols] = size(B)
%% new vector will be vector form
C = vertcat(A,[B])

댓글 수: 3

It's not clear what the expected output is.
Vims
Vims 2023년 12월 13일
I need answer in the vector form as it shown in image attached.
Vims
Vims 2023년 12월 13일

댓글을 달려면 로그인하십시오.

 채택된 답변

madhan ravi
madhan ravi 2023년 12월 13일
[A, B.'] %?

댓글 수: 2

Wanted = [A; reshape(B.', [], 1)
Vims
Vims 2023년 12월 13일
I want function which also do the reverse. As the same format B was earlier. This is the another function. I think we have to use
[numRows,numCols] = size(B)

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

madhan ravi
madhan ravi 2023년 12월 13일
B = B.';
Wanted = [A; B(:)]

댓글 수: 1

Vims
Vims 2023년 12월 13일
correct but in reverse as same format or size. This is main part.
[numRows,numCols] = size(B)

댓글을 달려면 로그인하십시오.

Dyuman Joshi
Dyuman Joshi 2023년 12월 13일
I've demonstrated 2 methods here using reshape and colon, : . Refer to the documentation pages linked for more info.
Note that using semi-colon to concatenate is equivalent to vertcat.
A = [1;2;3];
B = [4 5 6;8 9 11];
%Method 1
C1 = [A; reshape(B.',[],1)]
C1 = 9×1
1 2 3 4 5 6 8 9 11
%Method 2
B = B.';
C2 = [A; B(:)]
C2 = 9×1
1 2 3 4 5 6 8 9 11

댓글 수: 3

Vims
Vims 2023년 12월 13일
I need reverse function too as it should be go same size and format. This is biggest issue for any size and shape of matrix.
Vims
Vims 2023년 12월 13일
I think we have to use something like
[numRows,numCols] = size(B)
Dyuman Joshi
Dyuman Joshi 2023년 12월 13일
편집: Dyuman Joshi 2023년 12월 13일
That's a good start.
Now, use indexing to split the data, and reverse the steps of method 1.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품

릴리스

R2023a

질문:

2023년 12월 13일

편집:

2023년 12월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by