# naming the figure in loop

11 Ansichten (letzte 30 Tage)
sanket neharkar am 21 Mai 2022
Kommentiert: Jan am 23 Mai 2022
i had written a code for 100 points and to have a leasr square fit i had too first 5 points and jiust slided it till the end now for that i lave lmited the loop till 95 and plotted a least cureve fit now i have to plot the last 5 points in a single plot how should i do that and also i have done a looping of first 5,7,9 points so i amgetting 3 graph now i have to name the 3 figures how can i do that
##### 5 Kommentare4 ältere Kommentare anzeigen4 ältere Kommentare ausblenden
Jan am 23 Mai 2022
Starting a function with clear all; is a waste of time only. This clears all variables of the local workspace, but there are non at the first line of a function. In addition it removes all loaded functions from the memory. Reloading them from the slow disk wastes time only. Therefore "clear all" is "cargo cult programming" and an anti-pattern.
Do not use "error" as a name of a variable, becuase this is an important Matlab function, which cannot be called anymore afterwards.
You want to draw all graphs to the same figure. Then do not create 3 figures by:
fig(i) = figure('name', sprintf('%d', i),'NumberTitle','off');

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Image Analyst am 22 Mai 2022
Bearbeitet: Image Analyst am 22 Mai 2022
The Savitzky-Golay filter is a sliding polynomial fit. You can set up a window width of 5 elements and slide it along your vector fitting each set of 5 numbers to a polynomial of order 1, 2, 3, or 4. The sgolayfilt() function in the Signal Processing Toolbox does this for you. You just give it your data, the window width you want, and the order of the polynomial and it returns the filtered output vector.
I'm attaching the 3 sgolayfilt() demos I have. Adapt as needed.
To name figures in a loop you can do this
for k = 1 : 3
hFig(k) = figure;
hFig(k).Name = sprintf('This is my figure #%d', k);
end
##### 0 Kommentare-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Kategorien

Find more on Digital Filtering in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by