MATLAB: How to add a set of 500 datas to workspace and plot them

import wizardplotworkspace

I have never used matlab. I have a set of 500 .ascii extensioned files. I open them in current folder. I click one of them and while holding it, I carry it to the workspace window. (this bring import wizard screen-I click next) I right click on the yellow colored ascii data on the workplace and plot it. then I need to save each of these plotted image in jpeg fomat. this needs to be done for each 500 items, I guess I need a script for this. but I dont know how to do it. Can someone help me please ?

Best Answer

  • Start with the FAQ at
    I strongly recommend using the dir solution to process the files returned.
    Something like the following should be a rough starting point...
    d=dir('*.ascii'); % the directory list of files--salt wildcard/extension to suit
    for i=1:length(d)
    data=textread(d.name(i)); % read a file
    plot(data(:,1),data(:,2)); % plot 2nd column vs first
    [~,name]=fileparts(d.name(i)); % get the root name of the file
    print -djpeg name % write to name[.jpg]
    close 1 % close that figure
    end