Prompt to import data from csv file with specific column vectors
Show older comments
Hi everyone,
My task is to have matlab allow a user to open a file with the ability to later use these column vectors in a plot on an interval. I've dabbled into using csvread, but I can't seem to get it to work properly, so thats why I've shifted gears to look into the import data tool, because it works and it doesn't skew some of the data points like other commands. However, to pass this code onto the next person, I want to make it as simple as possible where they could run the code to be prompted to pick a .csv file, wherever it may be on their computer.
The other part of my question has to do with the intervals of plotting points. These files will typically see about 11,000 rows of data. What I would like some help on, is an efficient way to change the amount of points called out. I imagine I will later implement some sort of loop to eliminate the need for the user to edit code for optimal data points.
Whatever hints, tips or tricks you have are all greatly appreciated!! Thank you!
Answers (1)
KL
on 9 Feb 2018
0 votes
One of the things I love about MATLAB is its extensive documentation. Here's a link for you
This does exactly what you intend to do. Combine it with a data importing function. If you're using relatively newer version, I'd highly recommend using readtable to import data.
Hope it helps!
8 Comments
Dylan Mecca
on 9 Feb 2018
KL
on 9 Feb 2018
A lot depend on the data you're playing with. Just attach (using the paperclip button) some sample data which replicates your situation.
Dylan Mecca
on 9 Feb 2018
Your CSV file behaves strangely. I reckon this has something to do with the encoding, probably from where you get the data. I opened it with notepad++ and saved it under a new name. Try this file (attached) and see if the read data is ok.
data = readtable('dummy_data.csv');
Is there a way I can tell matlab to ignore certain colums and the first row of data?
Yes, you could force your code to read only a certain range or ignore few rows/columns. Functions such as csvread or dlmread aren't necessarily bad. Just test each command with your code and see which one suits your needs.
I always find the See also section of the doc page really interesting, so have a look there as well. Another option is using good old textscan with fopen with a format text specifying how your file should be read. This gives you the explicit control of how you want to read your data.
You could use tic/toc to analyse your code's performance.
Dylan Mecca
on 9 Feb 2018
KL
on 9 Feb 2018
I tested the file before giving it to you. I could import all 10588 rows just without any problems.
Which version of MATLAB are you using? And on which OS are you running?
Dylan Mecca
on 9 Feb 2018
KL
on 9 Feb 2018
Hmm.. Do you have the file in the same folder as that of your prac8.m file? Nevertheless you could use absolute path since you get the path from uigetfile.
[FileName,PathName] = uigetfile('*.csv','Select the DVSS CSV file');
T = readtable(fullfile(PathName,FileName))
Also keep the whole thing in a folder where you have read/write access. If this doesn't resolve your issue, try the other commands such as csvread, dlmread, textscan etc.
Categories
Find more on Data Import and Export 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!