I have in my workspace two variables with different length how can I make them have same length in order to plot them in a graph ?

6 ビュー (過去 30 日間)
I have two different variables in my workspace and I want to plot them but they have different indice length one its 16x30000 and the other variable its 9x1200 What could I do ? any solutions?

回答 (1 件)

Shameer Parmar
Shameer Parmar 2016 年 6 月 24 日
Hello Manny Ram,
Let us consider Varibale A is having size of 16x30000 and B is having size of 9x1200
You can do this..
newRowLength = max(size(A,1),size(B,1));
newColLength = max(size(A,2),size(B,2));
if ((size(A,1)~=newRowLength) || (size(A,2)~=newColLength))
A(newRowLength,newColLength) = [0];
end
if ((size(B,1)~=newRowLength) || (size(B,2)~=newColLength))
B(newRowLength,newColLength) = [0];
end
Now A and B become of same length..
  2 件のコメント
Manny Ram
Manny Ram 2016 年 6 月 24 日
HI there, Thank you for answering. could tell me what size would it have ??
Shameer Parmar
Shameer Parmar 2016 年 6 月 27 日
As per my given example..
The size of A and B will be now 16 x 30000
But this is the generic code, you can apply on any size of matrix, and it will give you the size of matrix as (greater number of row x greater no of column)
For example: If you have matrix C of 5 x 100 and D matrix of 10 x 50, then this code will give you new matrix C of size 10 x 100 and D also of size 10 X 100.
So that you can perform further operation.

サインインしてコメントする。

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by