Question
I have emg signal (30000x4) and want to apply function on it in loop.... function waveLen = find_waveform_length(signal) sum=0; for i=2:length(signal) sum= sum + abs(signal(i)-signal(i-1)); end waveLen = sum; %%%%%% New file %%%%%%% load ('dath001.mat'); x = dath001; % 30000x4 for i = 1:4 waveLen(i) = find_waveform_length(x(i)) end but it give output of 0 0 0 0 instead if i run waveLen function separately it give output of 463.6428 200.0671 411.7511 372.9306 ... I want this output by simple apply loop command
Expert Answer
John Michell
PhD Expert
Answered Aug 31, 2026
What is the 'y' you have used in your main script loop? Its not defined anywhere. Use this line in main script:
waveLen(i) = find_waveform_length(x(:,i))
Since you have not shared your MAT file, I tried with a random 30000x4 matrix and it works.
Few other recommendations:
1) Put an 'end' for your function
2) Don't use variable 'i' or any other inbuilt Matlab variable as index in your 'for' loop.
100% Run Guarantee
3-Hour Fast-Track Delivery
Need a Custom Version or Complete Simulation for This Problem?
Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.
Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here
Related matlab Questions & Solutions
Browse All →
Explore similar technical troubleshooting questions and verified MATLAB solutions:
Ready-to-Run MATLAB & Simulink Projects
Browse All Projects →