How to multiply a matrix by 0?

Hello,
I have this file in .txt and i want to make a matrix and multiply it by 0 using matlab!
Can somebody help me? I've been looking at other videos and answers but can't work it out. Thanks!

Answers (1)

Why to muply the matrix by zero when the resul;t will be a matrix of the same size with zeros. If you need to create a matriz of the same size as your data, then this is the way:
clearvars
unzip('HSF_PVerde_Lvl1.zip');
D = readmatrix('HSF_PVerde_Lvl1.txt');
D0 = zeros(size(D)); % This is the way
D0A = D*0;
whos
Name Size Bytes Class Attributes D 160128x12 15372288 double D0 160128x12 15372288 double D0A 160128x12 15372288 double
D0
D0 = 160128×12
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
D0A
D0A = 160128×12
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

1 Comment

Why to muply the matrix by zero when the resul;t will be a matrix of the same size with zeros.
Most of the time that's correct. If nonfinite values are involved it's not.
A = [1 2 0; NaN Inf -Inf]
A = 2×3
1 2 0 NaN Inf -Inf
B = 0*A
B = 2×3
0 0 0 NaN NaN NaN

Sign in to comment.

Asked:

on 15 Feb 2023

Commented:

on 15 Feb 2023

Community Treasure Hunt

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

Start Hunting!