Change indices without changing value for a spatially dependent variable
조회 수: 1 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (1개)
Faiz Gouri
2017년 8월 17일
편집: Faiz Gouri
2017년 8월 17일
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!