How to use array data for successive operations

1 visualización (últimos 30 días)
laura bagnale
laura bagnale el 22 de Jul. de 2021
Respondida: laura bagnale el 27 de Jul. de 2021
Hello everyone,
I hope someone could help me.
I used the 'normalize' function for a set of data and then I used fitsurface to interpolate them with e surface in space. This is the code:
A = [4.6; 9.3; 13.9; 18.6; 23.5; 28.5];
X = normalize(A,'range');
B = [10; 20; 30; 40; 50; 60];
Y = normalize(B,'range');
C = [3.06; 2.56; 2.51; 2.54; 1.6; 1.9];
Z = normalize(C,'range');
plot3(X,Y,Z,'or');
fs=fit([X,Y],Z, 'poly22')
plot(fs, [X,Y],Z)
I would like to normalize each element of the three arrays through this following function:
xinorm = (xi - xmin)/ (xmax - xmin)
HOw can I call each individual element in the expression to obtain a new array with normalized elements?
For example:
one single normalized element of array A should be x2norm = (9.3 - 4.6)/(28.5 - 4.6). I would like to do this for all elements and obtain the vector with all normalized values, in the end to plot them and use fitsurface again.
Thank you very much for your help.
Regards,
Laura

Respuesta aceptada

Pavan Guntha
Pavan Guntha el 27 de Jul. de 2021
Hi Laura,
You could leverage vectorization techniques to solve the problem. Have a look at the following code:
A = [4.6; 9.3; 13.9; 18.6; 23.5; 28.5];
xiNorm = norm_func(A);
B = [10; 20; 30; 40; 50; 60];
yiNorm = norm_func(B);
C = [3.06; 2.56; 2.51; 2.54; 1.6; 1.9];
ziNorm = norm_func(C);
plot3(xiNorm,yiNorm,ziNorm,'or');
fs=fit([xiNorm,yiNorm],ziNorm, 'poly22')
plot(fs, [xiNorm,yiNorm],ziNorm)
function arrOut = norm_func(A)
minA = min(A);
maxA = max(A);
arrOut = (A - minA)./(maxA - minA);
end
Hope this helps!

Más respuestas (1)

laura bagnale
laura bagnale el 27 de Jul. de 2021
Hi Pavan,
thank you very much for your support! This helps a lot!
Best Regards,
Laura

Categorías

Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by