Effacer les filtres
Effacer les filtres

Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

Not enough input arguments

2 vues (au cours des 30 derniers jours)
Courtney
Courtney le 14 Mar 2013
Clôturé : MATLAB Answer Bot le 20 Août 2021
First attempt at ever writing a code with a friend. Our teacher has not taought us anything. Please help!
Not enough input arguments for line 17:
survival(X,Y)=(X.*R(i))+((1-X).*(R(i).*(0.5)/1+0.5))-(Y.*0.5);
whole matlab function is:
function [Survival]=tradeoff(X,Y)
% function [Survival,Predator,R]=tradeoff(a,r)
% 'a' should be a vector with varying numbers for different predator levels
% - one for the low end of the range considered, the other the high end
% There are one output.
% Survival - the males' survival
% X is alpha value a is between 0 and 1.
R=linspace(0,10,100);
% the above lets us consider 100 different males,
% resources varying between the lowest 0 and highest
% 10 value given as inputs
for i=1:length(R)
% this is the survival equation considering resources and predators
survival(X,Y)=(X.*R(i))+((1-X).*(R(i).*(0.5)/1+0.5))-(Y.*0.5);
end;
figure(1);
plot(R,survival,'g');
title('tradeoff')
xlabel('Resources')
ylabel('Survival');

Réponses (1)

Image Analyst
Image Analyst le 14 Mar 2013
Instead of
for i=1:length(R)
% this is the survival equation considering resources and predators
survival(X,Y)=(X.*R(i))+((1-X).*(R(i).*(0.5)/1+0.5))-(Y.*0.5);
end;
Just have this:
% this is the survival equation considering resources and predators
survival = (X.*R)+((1-X).*(R.*(0.5)/1+0.5))-(Y.*0.5);
You don't use (x,y) after survival because it's an array. And you don't use (i) after R because you can just use R and do the whole array in one shot (no for loop needed).

Cette question est clôturée.

Community Treasure Hunt

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

Start Hunting!

Translated by