Open selected csv file and plot

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 日

2 投票

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 件のコメント

noname
noname 2018 年 3 月 14 日
I can't get it plot. I only can open the file. It said:
Undefined function or variable 'fullFileName'.
Error in test (line 12) data = csvread(fullFileName);
Image Analyst
Image Analyst 2018 年 3 月 15 日
編集済み: Image Analyst 2018 年 3 月 15 日
I just tried it and it works fine. Do you NOT have this line of code in there:
fullFileName = fullfile(folder, baseFileName)
??? That defines the variable, but you're saying it tells you the variable is not assigned, meaning that you did not put the line of code in there. Attach your ACTUAL code if you need more help.
noname
noname 2018 年 3 月 15 日
Thanks, I will try it. Do you know how to plot it using boxplot? Again, thank you for your time.
Image Analyst
Image Analyst 2018 年 3 月 15 日
I don't use boxplot(). What I'd do is to look in the documentation for an example of how to use it.
noname
noname 2018 年 3 月 15 日
編集済み: per isakson 2018 年 3 月 16 日
So I basically copy and paste your code on my file. however, I got this error, do you think I need to change my csv format?
Error using dlmread (line 138)
Mismatch between file and format string.
Trouble reading number from file (row 1u, field 1u) ==>
numberone,numbertwo,numberthree\n
Error in csvread (line 47)
m=dlmread(filename, ',', r, c);
Error in test (line 16)
data = csvread(fullFileName);
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 件)

カテゴリ

ヘルプ センター および File ExchangeEnvironment and Settings についてさらに検索

タグ

質問済み:

2018 年 3 月 14 日

コメント済み:

2018 年 3 月 24 日

Community Treasure Hunt

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

Start Hunting!

Translated by