Issues with Creating a Function
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
I am trying to figure out what may be wrong with a function I created.
V2 is a vector that is 51X1000. I want to use my conclusion function on this vector. In each row of the vector the values get larger. Ex: (1,1)=50 and (2,1)=60. Through my function I am trying to show this consistent relationship that as you go down in rows, the values get larger, but my code is getting these results so I know I am doing something wrong.
I am trying to code for all the columns in the vector V2 if row 1 is greater than row 2 display a 1 in vector u, if row 2>row 3, display a 1, and so on.
If row 1<row 2 display a 2, if row 2<row 3 display a 2...
I don't know if maybe in my u(W)=1/2/0 if I need to do u(W,K) or something like that.
I am just confused what my function is actually doing because when I display 'u' the values are nothing like what I predicted (which would be all 2s).
function [message] = conclusion(A)
%UNTITLED3 Summary of this function goes here
% Detailed explanation goes here
[o,n]=size(A);
for W=1:o-1
for K=1:n
if abs(A(W,K))>abs(A(W+1,K))
u(W)=1;
elseif abs(A(W,K))<abs(A(W+1,K))
u(W)=2;
else
u(W)=0;
end
end
end
if u==0
message=disp('The results are inconconclusive.');
elseif u==1
y=input('Is this graph showing multiple values of length of the distributed load or multiples values of the force per meter value of the distributed load? Say either length or force.');
message=disp('As the value of the length of the distributed load increases, the internal load decreases.');
elseif u==2
y=input('Is this graph showing multiple values of length of the distributed load or multiples values of the force per meter value of the distributed load? Say either length or force.');
message=disp('As the value of the length of the distributed load increases, the internal load decreases.');
else
message='The results are inconconclusive.'
disp(num2str(u))
end
end
Sorry if my explanation/question is confusing. Any help is greatly appreciated! Let me know if you have any questions about what I am asking.
2 comentarios
Respuestas (1)
David Hill
el 19 de Abr. de 2020
function [message] = conclusion(A)
u=diff(A,1,1);
u(u<0)=1;
u(u>0)=2;
message='';%I don't know what you want you messages to be, they are confusing to me.
end
0 comentarios
Ver también
Categorías
Más información sobre Calculus en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!