Access the x and y values using cell index

6 次查看(过去 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
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)?
Lama Hamadeh
Lama Hamadeh 2022-3-29
I would like to be able to know the range of values of x and y in each cell. So for example, if I say what are the range of values of x and y in cell 4? I should have and . Hope this clarifies what I need to do.

请先登录,再进行评论。

回答(1 个)

Image Analyst
Image Analyst 2022-3-29
You can get the dividing values between each cell like this:
divisions = linspace(0, 1, 5)
divisions = 1×5
0 0.2500 0.5000 0.7500 1.0000

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by