Effacer les filtres
Effacer les filtres

Info

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

I face the error of "Index exceeds matrix dimensions". but i want to show all the elements of z(n) and want to sum them and mean them. my program is given below, plz help me out?

1 vue (au cours des 30 derniers jours)
Mehedi
Mehedi le 4 Juin 2014
Clôturé : MATLAB Answer Bot le 20 Août 2021
clc clear x1=5; x2=3; x3=2; p=cell(3,1); for i=1:3 if i==1 x1=6; elseif i==2 x1=7; elseif i==3 x1=8; end p{i}=[x1-x2; x1-x3]; if p{i}==[4;5] break end end for n=1:3 z(n)=(p{n} (1)) end

Réponses (1)

Roger Wohlwend
Roger Wohlwend le 4 Juin 2014
In the second iteration the if-condition p{i} == [4;5] becomes true and terminates the loop. p{3} stays empty. In the second for-loop you want to acces that empty field --> p{3}(1). Matlab does not allow it and throws an error.
Hint: instead of
p{i} == [4; 5]
write
isequal(p{i}, [4;5])
or
all (p{i} == [4;5])
And if you post code the next time, please format it as code.

Cette question est clôturée.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by