Open selected csv file and plot

조회 수: 4 (최근 30일)
noname
noname 2018년 3월 14일
댓글: noname 2018년 3월 24일
Hi everyone, I have excel file with many spreadsheets; I convert them into csv file. My problem I have now is I want to open the csv file using uigetfile, and plot that file. However, I don't know how to plot it since different file has different data size. Can anyone help me with that? Thanks alot.
  댓글 수: 1
noname
noname 2018년 3월 24일
I'd like to use the multiselect to open more than one file, then plot them, but I don't know how to approach it. I'd really appreciate if anyone could help me. Thanks alot!

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2018년 3월 14일
Try this:
% Have user browse for a file, from a specified "starting folder."
% For convenience in browsing, set a starting folder from which to browse.
startingFolder = pwd; % or 'C:\wherever';
if ~exist(startingFolder, 'dir')
% If that folder doesn't exist, just start in the current folder.
startingFolder = pwd;
end
% Get the name of the file that the user wants to use.
defaultFileName = fullfile(startingFolder, '*.*');
[baseFileName, folder] = uigetfile(defaultFileName, 'Select a file');
if baseFileName == 0
% User clicked the Cancel button.
return;
end
fullFileName = fullfile(folder, baseFileName)
data = csvread(fullFileName);
x = data(:, 1); % Or wherever
y = data(:, 2);
plot(x, y, 'b*-', 'LineWidth', 2);
grid on;
title('Y vs. X', 'FontSize', 20);
xlabel('X', 'FontSize', 20);
ylabel('Y', 'FontSize', 20);
  댓글 수: 7
per isakson
per isakson 2018년 3월 16일
편집: per isakson 2018년 3월 16일
>> m=dlmread( 'Book3.csv', ',', 1,0);
works fine, but
>> m=dlmread( 'Book3.csv', ',', 0,0);
Error using dlmread (line 147)
Mismatch between file and format string.
Trouble reading 'Numeric' field from file (row number 1, field number 1) ==>
numberone,numbertwo,numberthree,numberfour\n
You must chose values of r and c that doesn't include the header.
noname
noname 2018년 3월 24일
Thank you all for your help. I found my solution. :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by