how to multiply a number to matrix?

Hello everyone,
I have a matrix 180X360X1332 (Latitude X Longitude X Time). I want to multiply 30 at every fourth number of third demension (e.g., 1,5,9,13......1332)
I have tried this for vector data:
Y = 30*(1:4:1332);
How can I do this for matrix data?
Thanks

3 comentarios

Bruno Luong
Bruno Luong el 18 de Jul. de 2022
"a number 30 in time demension at interval of 4"
Not sure someone can understand this.
Aarti Soni
Aarti Soni el 18 de Jul. de 2022
@Bruno Luong I have updated my question. Hope this is clear now.
Bruno Luong
Bruno Luong el 18 de Jul. de 2022
If that is the case, see @vishweshwar samba answer

Iniciar sesión para comentar.

 Respuesta aceptada

vishweshwar samba
vishweshwar samba el 18 de Jul. de 2022
Editada: vishweshwar samba el 18 de Jul. de 2022
I assume that the matrix 180X360X1332 (Latitude X Longitude X Time) is a multidimentional array and you want to multiply a value of 30 to (Latitude X Longitude) in the interval of 4 wrt Time.
% By using the below for loop, created a matrix 'A' of dimension 180x360x1332 (Latitude X Longitude X Time)
for i = 1:1332
A(:,:,i) = ones(180,360);
end
% Now multiply a number 30 in time dimension at interval of 4(1:4:1332)
A(:,:,1:4:1332) = A(:,:,1:4:1332)*30;

8 comentarios

@vishweshwar samba @Bruno Luong I have tried this but not working
for i = 1:1332,
x = data(:,:,i);
y = x(:,:,1:4:1332)*30;
z(:,:,i) = y;
end;
Aarti Soni
Aarti Soni el 18 de Jul. de 2022
here the third dimension is rainfall data for 1332, so I want to multiply a value of 30 to rainfall data.
Bruno Luong
Bruno Luong el 18 de Jul. de 2022
Editada: Bruno Luong el 18 de Jul. de 2022
Remove the for-loop, just
data(:,:,1:4:end) = data(:,:,1:4:end)*30;
I dont understand why you are using for loop. Instead replace your code with the code mentioned below.
data(:,:,1:4:1332) = data(:,:,1:4:1332)*30;
If you prefer for-loop
z = data;
for i = 1:4:size(z,3)
z(:,:,i) = z(:,:,i)*30;
end
Aarti Soni
Aarti Soni el 19 de Jul. de 2022
Thanks @Bruno Luong it works
Aarti Soni
Aarti Soni el 14 de Oct. de 2022
I have one more question in this regard, suppose, I have a time series (1x48) and I want to extract values at particular interval. Means, I want to creat a new time series which will have only 12 values. e.g., 1,5,9,13,17, 21, 25, 29, 33, 37, 41, 45
How can I do this?
Thanks
Bruno Luong
Bruno Luong el 15 de Oct. de 2022
@Aarti Soni I suggest you to create a new thread and better description. Someone else can answer to you.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.

Preguntada:

el 18 de Jul. de 2022

Comentada:

el 15 de Oct. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by