Change indices without changing value for a spatially dependent variable

2 views (last 30 days)
Eric Daiber on 10 Aug 2017
Edited: Faiz Gouri on 17 Aug 2017
Hi all, I have a question about how to change my coordinate system. I use a data file to create a spatially dependent variable (K_final) with my origin in the lower left hand corner; I would like to change the coordinate system to the center of the model grid at this location (69,250,12) using the current coordinate system (cells). Each cell is 0.25 m/cell. I have given a sample portion of the K_final in the attachment, the .dat file was too large to attach.
How do I go about changing the indices of the matrix without changing the values?
clear
clc
nx = 49; ny = 49; nz = 5; %the model uses 499x499x24 cells
k = 1; %counter
average_K = 8; %avg K
variance_K_high = 4;
variance_K_mid = 1;
variance_K_low = 0.25;
fidin=fopen('cond_1.dat'); %data file used to create spatially dependent variable.
A=fscanf(fidin,'%f');
fclose(fidin);
K_final = zeros(nx,ny,nz); %attached below
for a=1:nx;
for b=1:ny;
for c=1:nz;
K_final(a,b,c) = average_K*exp((variance_K_low^0.5)*A(k,1));
k=k+1;
end
end
end
Thanks, Eric

Faiz Gouri on 17 Aug 2017
Edited: Faiz Gouri on 17 Aug 2017
I understand that you would like to change indices in matrix without changing values. One possible way to do that would be to create a new matrix with extra size(based on how much distance you would like to move your origin) Refer this doc that explains about reshaping and re-sizing matrix.
You may need to copy each element from old matrix at a correspoding index in new matrix.