function [y] = sample_for(x) %SAMPLE_FOR Summary of this function goes here % Adjust scores sent to the function as either scalar or vector depending on what was sent for x=1:10 y=x+((10/100)*x); end
Hey i need help with this. i am trying to have this function give me different values for each value of x i enter in the script but it keeps giving me just one value
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Brenda Egbe
le 21 Oct 2018
Réponse apportée : Image Analyst
le 21 Oct 2018
function [y] = sample_for(x)
%SAMPLE_FOR Summary of this function goes here
% Adjust scores sent to the function as either scalar or vector depending on what was sent
for x=1:10
y=x+((10/100)*x);
end
This is the function, but when I run it with lets say x=5 it gives me the result for x=10. I need it to give the correct value for each x I enter. please I need help!!
4 commentaires
madhan ravi
le 21 Oct 2018
Modifié(e) : madhan ravi
le 21 Oct 2018
select the code and press the code button{},see my answer below
Réponse acceptée
Image Analyst
le 21 Oct 2018
Try this:
clc;
x = 5;
y = sample_for(x) % Shows y = 5.5
x = 1:7
y = sample_for(x) % shows y = [1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7]
function y = sample_for(x)
%SAMPLE_FOR y = 1.1 times x. Works if x is a scalar or vector.
% Adjust scores sent to the function as either scalar or vector depending on what was sent
for k = 1 : length(x)
y(k) = x(k) + (10/100) * x(k);
end
end
You can copy and paste that all into one m-file and run it.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Multirate Signal Processing 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!