Adding values along different dimensions in an array
조회 수: 6 (최근 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!