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!

Antworten (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov am 15 Feb. 2023

0 Stimmen

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 Kommentar

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

Melden Sie sich an, um zu kommentieren.

Gefragt:

am 15 Feb. 2023

Kommentiert:

am 15 Feb. 2023

Community Treasure Hunt

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

Start Hunting!

Translated by