Clear Filters
Clear Filters

how to save the data in csv file from the plot

174 views (last 30 days)
Hi,
I am using the code below for extracting the wanted data from few excel files then plotting the extracting data but I am unable to save the plotted data into excel file. Can you guys help, please?
Code So Far:
% To access the folder
folder = fullfile('C:','Users','muhammad','Documents','1st_Yr','Experiments_2021','performance_110');
files = dir( fullfile(folder, '*.ods') );
% Reading and extracting data from 12 excel files hence plotting
for ii = 1:length(files)
data = readmatrix(fullfile(files(ii).folder,files(ii).name), 'NumHeaderLines', 1)
x= data(:,10)
y=data(:,4)
figure(1)
% Plotting data
plot(x,y,'x','LineWidth',0.5);
hold on
end
  4 Comments
Walter Roberson
Walter Roberson on 31 May 2021
It sounds like you want to save them numerically.
As you are processing a number of files, how do you want the values from one file to be arranged relative to the values for another file? For example are you wanting to write each one to a separate sheet? Are you wanting to write 2 * length(files) separate columns, alternating X and Y? (If so is it possible that different files are not the same size as each other?) Are you wanting to write all of the data together as a pair of columns, all of the first file then all of the second file, and so on? If so then how do you want to mark the boundary between files? Do you want to store the file name for every row? Do you want to store a "group number" (which in this case would be ii) for each row ?
muhammad choudhry
muhammad choudhry on 31 May 2021
I want to write the data in the following format:
column 4 and 10 from the file one
then column 4 and 10 from file 2
all them columns need to be saved into one separate file(in one sheet), column by column (column data are not of same size, they are different in length), yes all the data as a pair of column all of the first then second correct and so on correct!. Well, for now I do not need to mark the boundary between each file because they are random point generated using experimental trials and moving forward I want to fit the LOWESS estimation curve to them to see how well or close them points to each other.

Sign in to comment.

Accepted Answer

KALYAN ACHARJYA
KALYAN ACHARJYA on 31 May 2021
Edited: KALYAN ACHARJYA on 31 May 2021
Options:
  1. The plot is a figure, you can save as Matlab .fig files (Use save as option)
  2. Save the figure plot result as an image (imwrite)
  3. If you wish to save x & y numeric data, create a vector as follows & save using writematrix function (Excel/CSV)
result=[x_column_data,y_column_data]
writematrix(result,......) %see the write matrix Matlab Doc
  2 Comments
muhammad choudhry
muhammad choudhry on 31 May 2021
hi,
thanks for the help. I follow the doc and write the result into the file all good but it is only writting one set (last) of data from the plot not everything as I have around data of 12 plots on the graph.
result =[x,y]
writematrix(result,'M.csv')
Walter Roberson
Walter Roberson on 31 May 2021
You can use 'writemode', 'append' for writematrix()

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!