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

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

Beginner's Question: What is wrong with this function?

Asked by Yun Inn on 10 Jul 2012

I am a beginner. Can someone tell me why the function won't work when I run:

[output]=XIOdicomread2('XIOM01.txt',110);

__________________________________________________________________________

function [Id]=XIOdicomread2(filename, SIMD)
%%%SIMD is the source to image distance.
importXIO(filename);
Id=data;
Id=double(Id);
f=100/SIMD;
if f<1
    Id=shrink(Id,f);
elseif f>1
    Id=expand(Id,f);
end
end
_____________________________________________________________________________

Where 'importXIO' import .txt file to MATLAB:

function importXIO(fileToRead1)
%IMPORTFILE(FILETOREAD1)
%  Imports data from the specified file
%  FILETOREAD1:  file to read
%  Auto-generated by MATLAB on 22-Jun-2012 10:05:03
DELIMITER = ',';
HEADERLINES = 16;
% 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

____________________________________________________________________________

error message is:

Undefined function or variable 'data'.

Error in ==> XIOdicomread2 at 8 Id=data;

Error in ==> test at 16 [output]=XIOdicomread2('XIOM01.txt',110);

3 Comments

Adrian Dronca on 10 Jul 2012

It searches for data and it tries to resolve it either as a variable or as a function.

In your case, you probably don't have data in your workspace and there is no such function on your MATLAB search path.

Maybe you should have passed the variable as a parameter, I`m not sure what you wanted.

Walter Roberson on 10 Jul 2012

It might work if you change

Id=data;

to

Id = evalin('base', 'data');

Yun Inn on 10 Jul 2012

evalin works! Thank you so much!

Yun Inn

Tags

Products

No products are associated with this question.

0 Answers

Contact us