How do i extract 'x' and 'y'data from 'z'data? f(x,y)=z
1 回表示 (過去 30 日間)
古いコメントを表示
I have 'x' data, 'y' data, 'z1' data 'z2' data.
It has two variable values('z1', 'z2') at the same coordinates(x,y).
x : an integer from 1 to 13
y : an integer from 1 to 19
Z1: 13*19
I used cftool to plot the mesh. ( Interpolation)
How do I extract 'x' and 'y' data from 'z1' 'z2'?
I want to estimate the coordinates by comparing the x,y data( extracted through z1)
with the x,y data (extracted through z2).
A simple example is similar to finding approximate coordinates by estimating longitude based on time and latitude based on temperature, (confined to a northern (lower hemisphere) region.)
After moving the cftool result to the workspace (name: fittedmodel_z1), in the command window, use a value with a decimal point, not an integer, within the range (~13, ~19) for x and y, such as 'fittedmodel_z1(10.1,3.7)' When I give the command, I can get z1 data.
How do I do it in reverse?
I want to use f(x,y)=a , but I don't know the function f(x,y) .
Cannot use formula(fittedmodel_Z1).
>> formula(fittedmodel_Z1)
ans =
'piecewise linear surface'
I just want to know the coordinates through the overlapping part like the red hatched part in the picture below.
How about using artificial intelligence like a classification model? Or fuzzy?
Thank you.
1 件のコメント
Mathieu NOE
2021 年 9 月 8 日
hello
you need to do a 2D interpolation , see :
help interp2
interp2 2-D interpolation (table lookup).
回答 (1 件)
TED MOSBY
2024 年 6 月 9 日
Hi Lilo,
To estimate the coordinates ‘x’ and ‘y’ from the values ‘z1’ and ‘z2’, given that you have models ‘fittedmodel_z1’ and ‘fittedmodel_z2’ you need to perform an inverse prediction. There isn't a direct function in MATLAB for performing this inverse operation, you'll have to use an optimization approach where you minimize the difference between the observed (z) values and the model predictions for (z).
- Create an objective function that will calculate the error:
function error = objectiveFunctionZ1(xy, z1_observed, fittedmodel_z1)
% xy is a vector where xy(1) = x and xy(2) = y
% Calculate the predicted z1 based on the current x and y
z1_predicted = feval(fittedmodel_z1, xy(1), xy(2));
% Calculate the difference (error) between observed and predicted z1
error = abs(z1_predicted - z1_observed);
end
- You can use MATLAB’s optimization functions such as “fminsearch“to find the (x) and (y) that minimize the error defined in your objective function as shown below:
% Observed z1 value for which you want to find the corresponding x and y
z1_observed = 5; % Example value
% Initial guess for x and y
initialGuess = [6, 10]; % Adjust based on your data range
% Optimization to find x and y that minimize the error for z1
[estimatedXY, fval] = fminsearch(@(xy) objectiveFunctionZ1(xy, z1_observed, fittedmodel_z1), initialGuess, options);
% Extracting estimated x and y
estimatedX = estimatedXY(1);
estimatedY = estimatedXY(2);
- Repeat the above steps for z2
You may refer to the MATLAB documentation for “fminsearch” here:
Hope it helps!
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Statistics and Machine Learning Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!