Adding values along different dimensions in an array

7 ビュー (過去 30 日間)
Prerna Mishra
Prerna Mishra 2022 年 7 月 5 日
回答済み: Siraj 2023 年 8 月 30 日
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 件のコメント
Walter Roberson
Walter Roberson 2022 年 7 月 5 日
編集済み: Walter Roberson 2022 年 7 月 5 日
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 2022 年 7 月 5 日
Ah, sorry. I sse now where I am visualizing this wrong.
Thanks!

サインインしてコメントする。

回答 (1 件)

Siraj
Siraj 2023 年 8 月 30 日
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.

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by