10-01-2011 08:46 AM - edited 10-01-2011 08:54 AM
Dear All,
I have the following MATLAB code. I tried it in mathscript node in Labview 8.6, but the execution was slow.
How can this be converted into Labview.
X: array that contains max values
S: orginal signal
for i= 1 : (length(X)-1)
if (X(i+1)-X(i)<50)
m(k)=S(X(i));
k=k+1;
else
m(k)=S(X(i));
[mx,ind]= max(m(1:k));
max_val(n)= mx;
max_ind(n)=X(ind);
m=0;
k=k+1;
n=n+1;
end
end
Thanks
Your help is much appreciated.
10-01-2011 12:13 PM
Hi,
I can either tell you how to do it, or teach you. What would you prefer?
Regards,
Prashanth
10-01-2011 12:34 PM
Hi Pachi,
Of course I prefer to teach me. Alot of my coding depends on getting to know how to do it.
Regards,
10-01-2011 01:20 PM
Why don't you attach your matlab code and include some typical data.
Why is "m(k)=S(X(i));" in both cases. Wouldn't it be sufficient to have it once before the decision then?
10-01-2011 02:54 PM - edited 10-01-2011 02:59 PM
Dear altenbach,
The two statements should be there to include the last point of X since the for loop i=1:length(X) - 1
Look at the attached sample data and m file.
Regards,
10-02-2011 01:13 AM
AR_1000,
Are you comfortable using lor loops and case structures in LabVIEW?
If not, here are some useful links:
https://decibel.ni.com/content/docs/DOC-15757
http://zone.ni.com/reference/en-XX/help/371361H-01/glang/case_structure/
https://decibel.ni.com/content/docs/DOC-17034
Your code needs a very simple understanding of how loops and case structures work, and the basics of input/output (controls/indicators)
Regards,
10-02-2011 07:52 AM
Tanks Pachi for the links.
I think I know how to use loops and cases .
The main problem how to handle arrays and their elements inside looping structures as described in the matlab code above.
10-02-2011 07:56 AM
Yes, for that you will need to know the concept of auto-indexing in loops.
LabVIEW allows you to automatically access each element of an array in an iteration by auto-indexing.
For your application, use a array control or constant autoindexed to a for loop (note that you no longer have to tell the loop what the value of N is)
10-02-2011 08:42 AM
Please at the VI attached. It is a simple try to implement what I understand so far. But I could not complete it.
Any suggestions?
10-02-2011 10:10 AM
Hi,
This is exactly why I asked you to study auto-indexing and shift registers, These concepts inside loops greatly ease your programming in LabVIEW.
Here's a quick introduction to them:
When you wire a signal into and out of a loop, you can either have a tunnel, auto-indexed tunnel, or a shift register.
A tunnel takes a copy of the value and uses this for each loop iteration.
An unto-indexed tunnel indexes out elements of an array for each iteration
A shift register is a feedback loop and sends the output of an interation to the next.
For your application, your S needs to be a tunnel and X needs to be auto-indexed. Right click the tunnel (orange box on the loop) on the X signal and click "Enable Indexing". Notice that you no longer need to wire the N-input of the for loop. It understands that the loop should run for each element of X.
Regards