Info

此问题已关闭。 请重新打开它进行编辑或回答。

Not enough input arguments

2 次查看(过去 30 天)
Courtney
Courtney 2013-3-14
关闭: MATLAB Answer Bot 2021-8-20
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');

回答(1 个)

Image Analyst
Image Analyst 2013-3-14
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).

此问题已关闭。

Community Treasure Hunt

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

Start Hunting!

Translated by