Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Import data using import wizard code generation

Subject: Import data using import wizard code generation

From: Jac

Date: 24 Sep, 2012 00:39:09

Message: 1 of 2

Hey guys, haven't used the code generation function using the import wizard before, was hoping someone could explain to me how it works.

I have my file called 'World Population.csv' Using the wizard i get my data in the format i want, then check the 'code generation' box.

I get a generic function generated like this:
function importfile1(fileToRead1)
%IMPORTFILE1(FILETOREAD1)
% Imports data from the specified file
% FILETOREAD1: file to read

% Auto-generated by MATLAB on 24-Sep-2012 10:32:32

DELIMITER = ',';
HEADERLINES = 3;

% Import the file
newData1 = importdata(fileToRead1, DELIMITER, HEADERLINES);

% Create new variables in the base workspace from those fields.
vars = fieldnames(newData1);
for i = 1:length(vars)
    assignin('base', vars{i}, newData1.(vars{i}));
end

But i dont know how to get the data i want defined in a file after this. The error message is often that there are too many output arguments. Can someone show me how this generic function should be modified for my purposes, or what i have to define in my m-file before using this generic function.


Any help would be greatly appreciated. Thanks!

Subject: Import data using import wizard code generation

From: Ryan

Date: 21 Oct, 2012 18:36:08

Message: 2 of 2

File > Import Data > Open > Import as Column Vectors . . . most likely . . . .
Import > Generate Script

That should pretty much do it for you.



"JRicard" wrote in message <k3oa3d$6go$1@newscl01ah.mathworks.com>...
> Hey guys, haven't used the code generation function using the import wizard before, was hoping someone could explain to me how it works.
>
> I have my file called 'World Population.csv' Using the wizard i get my data in the format i want, then check the 'code generation' box.
>
> I get a generic function generated like this:
> function importfile1(fileToRead1)
> %IMPORTFILE1(FILETOREAD1)
> % Imports data from the specified file
> % FILETOREAD1: file to read
>
> % Auto-generated by MATLAB on 24-Sep-2012 10:32:32
>
> DELIMITER = ',';
> HEADERLINES = 3;
>
> % Import the file
> newData1 = importdata(fileToRead1, DELIMITER, HEADERLINES);
>
> % Create new variables in the base workspace from those fields.
> vars = fieldnames(newData1);
> for i = 1:length(vars)
> assignin('base', vars{i}, newData1.(vars{i}));
> end
>
> But i dont know how to get the data i want defined in a file after this. The error message is often that there are too many output arguments. Can someone show me how this generic function should be modified for my purposes, or what i have to define in my m-file before using this generic function.
>
>
> Any help would be greatly appreciated. Thanks!

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us