Hello friends,I have parametric equation about 5 paper,I want to add dot for every * and / signs to use linspace.How can I do automatically

1 Kommentar

Rik
Rik am 6 Mai 2019
Have a read here and here. It will greatly improve your chances of getting an answer.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Star Strider
Star Strider am 6 Mai 2019
Bearbeitet: Star Strider am 6 Mai 2019

2 Stimmen

Use the vectorize (link) function.
The only change you temporatily need to make is to create your function as a character vector by putting single quotes (') around it first, then removing them from the vectorize output.
Example —
f = exp(-0.1*t) * sin(2*pi*t);
fv = vectorize('exp(-0.1*t) * sin(2*pi*t)')
producing:
fv =
'exp(-0.1.*t) .* sin(2.*pi.*t)'
You then have to manually edit your expression to put it back as a valid expression. That simply means removing the single quotes:
f = exp(-0.1.*t) .* sin(2.*pi.*t)
and your expression is vectorized, ready for your linspace arguments!
EDIT — Corrected typographical errors.

4 Kommentare

Rik
Rik am 6 Mai 2019
Nice function. It turns out you still keep learning about functions that have been around for ages.
Star Strider
Star Strider am 6 Mai 2019
@Rik — Thank you!
That’s certainly my experience, too. I learn about a lot of functions — at least some of which I believe I should already know — when others mention them here on Answers. Even going through the Release Notes does not always uncover all of them, since there are so many.
Ertan Aras
Ertan Aras am 6 Mai 2019
Thanks a lot.I ve solved this problem utilizing vectorize functions.
Star Strider
Star Strider am 6 Mai 2019
As always, my pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

gonzalo Mier
gonzalo Mier am 6 Mai 2019

0 Stimmen

You have two possibilities here:
  1. In the text file, you replace * by .* and / by ./ in all the document (there is an option in the replace to replace all).
  2. If you have it like a function and want to do it by programming, you can overload the funtion mtimes and mrdivide by times and rdivide as:
function c = mtimes(a,b), c = times(a,b); end
function c = mrdivide(a,b), c = rdivide(a,b); end
You can add this to the end of your file or to your folder.
By preference, always do the first method, as overloading operators is not a good practice unless you try to ofuscate your code, but I have found some moments where it's the only way

Kategorien

Mehr zu Programming finden Sie in Hilfe-Center und File Exchange

Tags

Noch keine Tags eingegeben.

Community Treasure Hunt

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

Start Hunting!

Translated by