MATLAB: Finding data in a matrix

findmatrix

Hi all,
I am in a trouble 🙁 i do have a matrix of 251*28 that I want to extract the data by giving x and y values (columns(28) and rows(251)). ex
ineedX = find(Xgrid >= 12 & Xgrid <=60); % the extracted data

ineedY = find(Zgrid>= -75 & Zgrid <=-60); % the extracted data
the find command is not working when I want to apply the function as it gives a vector which I want the matrix.
any help? Thanks a lot!

Best Answer

Depending on how your data is organized, (you did not tell if x is first index or second) after doing
ineedX = find(Xgrid >= 12 & Xgrid <=60); % the extracted INDEX

ineedY = find(Zgrid>= -75 & Zgrid <=-60); % the extracted INDEX
you should do
DataExtract = Data(ineedX,ineedY)
Where Data is your original matrix. Or the reverse in indexes if you have x in second dimension.