hi
I have the following matrices
h = 5.1000 3.5000 1.4000 0.2000
6.4000 3.2000 4.5000 1.5000
5.4000 3.4000 1.7000 0.2000
5.7000 2.8000 4.5000 1.3000
5.7000 4.4000 1.5000 0.4000
5.6000 2.9000 3.6000 1.3000
k = 5.1000 3.8000 1.9000 0.4000
6.4000 2.9000 4.3000 1.3000
4.3000 3.0000 1.1000 0.1000
5.4000 3.0000 4.5000 1.5000
I want to make K =
5.1000 3.8000 1.9000 0.4000
6.4000 2.9000 4.3000 1.3000
4.3000 3.0000 1.1000 0.1000
5.4000 3.0000 4.5000 1.5000
0.0000 0.0000 0.0000 0.0000
0.0000 0.0000 0.0000 0.0000
so that it has the same dimension as h. How do i do that. Thanks in advance
Tino

 채택된 답변

KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 5월 3일
편집: KALYAN ACHARJYA 2019년 5월 3일

0 개 추천

[rows1 colm1]=size(h);
[rows2 colm2]=size(k);
% You can change the way depending on sizes of h and k
% Also which direction you want to pad zeros
k_revise=[k;zeros(rows1-rows2,colm1)];
5.1000 3.8000 1.9000 0.4000
6.4000 2.9000 4.3000 1.3000
4.3000 3.0000 1.1000 0.1000
5.4000 3.0000 4.5000 1.5000
0 0 0 0
0 0 0 0
There are more smart way to do the same, please follow padarray

댓글 수: 4

Tino
Tino 2019년 5월 3일
Thanks Kalyan
KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 5월 3일
편집: KALYAN ACHARJYA 2019년 5월 3일
Welcome @Tino Please check this link also.
Tino
Tino 2019년 5월 3일
ok Kalyan
But if I want to make it 0.0000 instead of using a single 0 how do I go about it
thanks again
>> format long
>> rand(2,2)
ans =
0.141886338627215 0.915735525189067
0.421761282626275 0.792207329559554
>> format short
>> rand(2,2)
ans =
0.9595 0.0357
0.6557 0.8491
or you are looking different, please check
Good Wishes!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Large Files and Big Data에 대해 자세히 알아보기

제품

릴리스

R2019a

태그

아직 태그를 입력하지 않았습니다.

질문:

2019년 5월 3일

편집:

2019년 5월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by