Adding values along different dimensions in an array

7 views (last 30 days)
I have an array kdsimind that has dimensions 5000X5000X35. I want to initialize is such that along the first dimension I have floor(nk/2) and along the second dimension I have floor(nd/2) and along the third dimension I have 1. How do I do this? I know how to do in 2 dimension, like if I had 5000X35 I could have written
kdsimind(:,1)=floor(nk/2)
  4 Comments
Walter Roberson
Walter Roberson on 5 Jul 2022
Edited: Walter Roberson on 5 Jul 2022
kdsimind(:,1)=floor(nk/2)
That initializes the first column, not the first dimension.
The way you have phrased the question is contradictory. Suppose you have a piece of paper and you say, "As you go along the rows, all of the rows should have the value 250, and as you go along the columns, all of the columns should have the value 125. Then the entry at (1,1) is in a row, so according to the first instruction it needs to have the value 250, but the entry at (1,1) is also in a column, so according to the second instruction it needs to have the value 125... and no individual location can be both 250 and 125.
Prerna Mishra
Prerna Mishra on 5 Jul 2022
Ah, sorry. I sse now where I am visualizing this wrong.
Thanks!

Sign in to comment.

Answers (1)

Siraj
Siraj on 30 Aug 2023
Hii! It is my understanding that you have a 3D array “kdsimind” of dimensions 5000X5000X35.
You want to initialize the first dimension of this array as “floor(nk/2)”, the second dimension of the array as “floor(nd/2)” and third dimension as 1.
Now I am not sure what you mean when you said to initialize the first dimension.
As per my understanding, I am attaching a code below that can be used to initialize the array.
matrix = zeros(5000,5000, 35);
nk = 500;
nd = 250;
%% Initialzing first dimension;
matrix(:,1,1) = floor(nk/2);
%% Initialzing second dimension;
matrix(1,:,1) = floor(nd/2);
%% Initialzing third dimension;
matrix(1,1,:) = 1;
Refer to the documentation below to learn more about array indexing.

Tags

Products

Community Treasure Hunt

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

Start Hunting!