Adding values along different dimensions in an array
4 次查看(过去 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
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.
回答(1 个)
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!