is there a command similar to map() that you can use in Matlab

6 vues (au cours des 30 derniers jours)
andre ivo vieira
andre ivo vieira le 1 Mai 2023
good morning , I would like to know if the Arduino IDE has a second command map(val, 0, 1023, 0, 255); where we can read a potentiometer placed on one of the Arduino's analog ports and apply a pwm value to one of the pwm outputs of the arduino uno.
In Matlab is there anything similar to this command, can anyone tell me?
I am doing the communication from the Arduino via Matlab only and for that I downloaded some support packages for Matlab to communicate with the Arduino, so I don't need the (Arduino IDE) to program.
In these packages there are some examples, but for what I want there are not, so I wanted to know if there is any other command that is similar to the one used in Arduino to be used in Matlab without the need to use the Arduino IDE only Matlab

Réponses (2)

Cris LaPierre
Cris LaPierre le 1 Mai 2023
This sounds similar to what the rescale function does.

Stephen23
Stephen23 le 1 Mai 2023
"In Matlab is there anything similar to this command, can anyone tell me?"
MAP is just a very basic kind of interpolation. MATLAB has many interpolation routines:
For example, using the first MAP example:
x = 2;
y = interp1([1,50],[50,1],x)
y = 49
Note that MATLAB's interpolation routines all operate and return floating point numbers. The MAP documentation specifically states that it performs integer arithmetic: so user beware!
Also note that the MAP documentation gives the formula under "Appendix". That formula is also trivial to implement as very basic MATLAB code, again using the same example:
in_min = 1;
in_max = 50;
out_min = 50;
out_max = 1;
out = (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min
out = 49
Making that more MATLAB-y (e.g. to work on vectors) is left as an exercise for the reader.

Catégories

En savoir plus sur Instrument Control Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by