Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

Not enough input arguments

1 visualizzazione (ultimi 30 giorni)
Courtney
Courtney il 14 Mar 2013
Chiuso: MATLAB Answer Bot il 20 Ago 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');

Risposte (1)

Image Analyst
Image Analyst il 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).

Questa domanda è chiusa.

Community Treasure Hunt

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

Start Hunting!

Translated by