Question

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

  2. I wonder why the arr never adds up to 30 and 40 etc

My system is as follow:

enter image description here

The codes are here:

enter image description here

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

Was it helpful?

Solution

Before the final end, insert

scalar_value = arr(count,1);

and declare your function as

[arr, scalar_value] = fcn(signal,V,count)

This will get the value of interest (scalar_value) in the 4x1 vector arr, without disrupting the arr logic.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top