Access the x and y values using cell index
7 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Image Analyst
il 29 Mar 2022
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)?
Risposte (1)
Image Analyst
il 29 Mar 2022
You can get the dividing values between each cell like this:
divisions = linspace(0, 1, 5)
0 Commenti
Vedere anche
Categorie
Scopri di più su Matrix Indexing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!