How do I plot a graph linearly spaced by N elements?
Mostrar comentarios más antiguos
I have to create a poligonal graph and calculate its lenght, and this is the first step: evenly spacing the graph of the f = x^2 function. I wrote the code and it gives me just a blank plot. Here's the code, I don't know what's wrong with it. I'd ble glad if someone helped me.
clc; clear all; close all;
function f = exponecial(N)
for x = linspace(0, 1, N)
f = x^2;
endfor
end
figure (1);
hold;
for N = 0:1:10
plot(N, exponecial(N))
endfor
3 comentarios
the cyclist
el 18 de Jul. de 2021
There is quite a lot wrong with this code:
- endfor is not valid MATLAB syntax
- you are mixing some vector notation and scalar notation
- it is not clear how you are calling this code, and where you are placing the function definition
- you don't really need the subfunction at all
Without a doubt, someone here could (and probably will) just rewrite your code from scratch, and you'll have your answer. But it seems to me that you have learned a different language previously, and are trying to apply some MATLAB coding ideas to what you know. So, if you actually want to learn MATLAB, and not just have someone do your work for you, I would recommend the MATLAB Onramp tutorial.
VBBV
el 19 de Jul. de 2021
It seems you know microsoft Visual Basic programming well. But in matlab environemnt those syntax may not work correctly.
Gabriel Donato
el 19 de Jul. de 2021
Editada: Gabriel Donato
el 19 de Jul. de 2021
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Octave en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
