Assigning values in a vector array to a column in an array
25 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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!
0 Kommentare
Antworten (1)
Rishabh Mishra
am 20 Jan. 2021
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.
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!