Assigning values in a vector array to a column in an array

조회 수: 27 (최근 30일)
Anna Hayden
Anna Hayden 2021년 1월 17일
댓글: Anna Hayden 2021년 1월 21일
Hello,
I have a column vector of size 20073 x 1 from a previous model output (the steady state run), and I would like to copy all the values from the column vector into the corresponding indices of the first column of an array of size 20073 x 688 in my transient run. After that first column in the array is populated, I want to fill the rest of the array with values that I calculate in the latter part of the for loop. However, I keep running into matrix size, compatibility, and index errors.
I have attached the code I am having probems with (non_steady_state_thick_change.m). I have written a similar code for the steady state run (thick_change_spatially_var.m, attached), but I don't run into any errors and the code runs without any problem.
Here are some sizes and properties of the variables in the functions:
In thick_change_spatially_var.m (corresponding to the steady state run)
store_thickness = zeros(length(xy),length(pt.out_t)); % the size of xy is 20073 x 2, pt.out_t is 1 x 334, so store_thickness is 20073 x 334
surf_test = zeros(length(xy),length(pt.out_t));% the size of xy is 20073 x 2, pt.out_t is 1 x 334, so store_thickness is 20073 x 334
dt = pt.out_t(2) - pt.out_t(1); %30 days, in seconds
thinning_rate_downglacier = 1/pp.year; %pp.year is seconds per year
thinning_rate_upglacier = 0.5/pp.year;
pp.topo.slope_factor % 1x1 double
In non_steady_state_thick_change.m (corresponding to the transient run
store_thickness = zeros(length(xy),length(pt.out_t)); %the size of xy is 20073 x 2, pt.out_t is 1 x 668, so store_thickness is 20073 x 668
surf_test_transient = zeros(length(xy),length(pt.out_t));%the size of xy is 20073 x 2, pt.out_t is 1 x 668, so store_thickness is 20073 x 668
dt = pt.out_t(2) - pt.out_t(1);
thinning_rate_downglacier = 1/pp.year;
thinning_rate_upglacier = 0.5/pp.year;
% pin.ice_thickness_surf_start_val : ice_thickness_surf_start_val is 20073 x 1
Does anyone have any suggestions?
Thanks!

답변 (1개)

Rishabh Mishra
Rishabh Mishra 2021년 1월 20일
Hi,
Based on my understanding of the issue described by you, I have created a simple code imitating the process you implemented in your code files. Here it goes,
mat = zeros(5,7); % create 2D vector (matrix)
col = rand(5,1); % create column vector
for k = 1:7 % loop through the process
col = col+1; % calculate other columns
mat(1:5,k) = col; % assign values to each matrix column
end
Hope this helps.
  댓글 수: 1
Anna Hayden
Anna Hayden 2021년 1월 21일
Thanks for your input. However, your code doesn't imitate what I'm hoping to do.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by