Dimensionality issue with Matlab Function

I thought this should be fairly simple, I really have no idea what went wrong, been trying for a week, gosh!! so ashamed of myself.
I define the following at Workspace: I=[5 5.1 5.2 5.2]; V=[95 80 85 20];
I expect an output like this: at t=0, arr=20, at t=1, arr=30, at t=2, arr=40,
When I run the simulation, what I got is: at t=0, arr=20, 0, 0, 0, at t=1, arr=0, 10, 0, 0, at t=2, arr=0, 0, 10, 0,
There are few problems with this result: 1. I expect only one arr value at a particular time, but it came out four arr values at a time
I wonder why the arr never adds up to 30 and 40 etc My system is as follow: http://imgur.com/nEKDqqS
The codes are here: http://imgur.com/Cipjbyn

6 comentarios

want2know
want2know el 4 de Nov. de 2013
i managed to get only one value at a time, but why the arr never adds up to 30 and 40 etc? it keeps detecting that arr(count-1,1) is ALWAYS zero
Wayne King
Wayne King el 4 de Nov. de 2013
You should show the code you've written
Walter Roberson
Walter Roberson el 4 de Nov. de 2013
The MATLAB part of the code does not change "count", so you need to demonstrate that something will be changing "count"
want2know
want2know el 5 de Nov. de 2013
Thanks for your reply,Walter. I enable debugging and I am sure the count did increase from 1 to 2, 3 and so on. However, the integ_signal(count,1) contains very weird value such as 0.3412 etc. I have no idea what went wrong in this simple code
want2know
want2know el 5 de Nov. de 2013
Editada: want2know el 5 de Nov. de 2013
function ar = fcn(signal, V, count)
integ_signal=zeros(4,1); arr=zeros(4,1);
if count<=(length(signal)) if count==1 integ_signal(count,1) = 20; % Initial Condition arr(count,1)= integ_signal(count,1); else integ_signal(count,1) = arr(count-1,1) + 10; arr(count,1)= integ_signal(count,1); end end
ar = arr(count,1);
end
want2know
want2know el 5 de Nov. de 2013
I run the codes in m file without any function, it did gives me correct value, 20, 30,40. but i dont know why when I combine all the blocks in Simulink, the value stays at 10 all the time

Respuestas (0)

La pregunta está cerrada.

Preguntada:

el 4 de Nov. de 2013

Cerrada:

el 20 de Ag. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by