Equality error
Afficher commentaires plus anciens
function varargout=practice(varargin)
clc
idols(1).groupname = '2pm';
idols(1).nummembers = 1;
idols(1).gender = 'boys';
idols(1).debut = 2008;
idols(1).member(1).name = 'chansung';
idols(1).member(1).birthyear = 1990;
idols(1).member(1).height = 184;
idols(1).member(1).blood = 'B';
idols(2).groupname = 'SNSD';
idols(2).nummembers = 2;
idols(2).gender = 'girls';
idols(2).debut = 2007;
idols(2).member(1).name = 'taeyeon';
idols(2).member(1).birthyear = 1989;
idols(2).member(1).height = 'NA';
idols(2).member(1).blood = 'O';
idols(2).member(2).name = 'jessica';
idols(2).member(2).birthyear = 1989;
idols(2).member(2).height = 'NA';
idols(2).member(2).blood = 'B';
result=calc_avgage(idols, '2pm', 'SNSD');
disp(result)
end
function out=calc_avgage(idols, varargin)
n=0;
sum=0;
idols(2).member(1).birthyear
for i=1:nargin-1
idols2(i).groupname=char(varargin(i));
end
for i=1:length(idols2)
for j=1:length(idols)
a=idols2(i).groupname;
b=idols(j).groupname;
if a==b
for k=1:idols(j).nummembers
sum=sum+idols(j).member(k).birthyear;
n=n+1;
end
end
end
end
sum
n
out=sum/n;
end
If I run this code, why is it that when a==b, the code runs well
However when a~=b, the Matlab program gives the error
??? Error using ==> eq
Matrix dimensions must agree
How would I fix the problem?
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Data Types dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!