Access the x and y values using cell index
조회 수: 5 (최근 30일)
이전 댓글 표시
Hi all,
I am trying to access the values of both x and y values using just the cell index similar to the structure shown below.

In other words, I am trying to answer the questions: what is the values of x and y in a given cell?
Here is my code.
close all;
clear all;
%set up the x axis
xmin = 0;
xmax = 1;
dx = 0.25;
x = linspace(xmin,xmax,5);
%set up the y axis
ymin = 0;
ymax = 1;
dy = 0.25;
y = linspace(ymin,ymax,5);
%calculate the mid points on x axis
xa = x(1:end-1);
xb = x(2:end);
Mid_x = (xb+xa)/2;
%calculate the mid points on y axis
ya = y(1:end-1);
yb = y(2:end);
Mid_y = (yb+ya)/2;
%construct the index matrix of the cells
N = numel(Mid_x);
M = numel(Mid_y);
NCells = M * N;
for i = 1:N
for j = 1:M
CellInd(i,j)= N*(i-1)+j;
end
end
Any help would be appreicted.
Thanks.
댓글 수: 2
Image Analyst
2022년 3월 29일
Not sure what you want or what you have. I don't think you are using a "cell array". I think you're using cell like how Excel calls cells, or else your cell is just a region of values in some gridded layout. Do you have some area that spans 0-1 in each direction and is divided up into 4x4 = 16 different regions (cells)? And you have some vector or array that defines where each region starts and stops? Well, for example in the lower left region going fromm 0-0.25 in both x and y, there are of course an infinite number of numbers in that region. Do you just want the coordinate of the middle point, like (0.125, 0.125)?
답변 (1개)
Image Analyst
2022년 3월 29일
You can get the dividing values between each cell like this:
divisions = linspace(0, 1, 5)
댓글 수: 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!