Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling another file to Interpolate from an Array ... 1

Status
Not open for further replies.

RoopB

Aerospace
May 24, 2010
6
US
Hello all,

I'm in the process of translating some old C++ code into Matlab in order to make my matrix and vector operations easier. I am still fairly novice with Matlab, so I've come upon a problem that I am not sure can be done the way I imagine it should work. My goal is to interpolate through a x-y matrix that is contained in a seperate .m file from my code.

I am trying to lay out my logic in this way for my program:
- Here is some input (including x, y, and the array name).
- Call File2 that contains the actual routine to interpolate in an array.
- Call File3 that holds my arrays.
- Find the array that I have specified.
- Interpolate from this array, given my inputs.
- Return the value to me.

My sticking point is trying to load the file that contians all of my arrays (I have many), where one array can be picked out and used.

Has anyone else done something similar to this before? I am not entirely sure how to work around this problem. I have sucessfully made a test interpolation from a small table, using interp1 with a .mat file, but I had to strip all of the headings and comments out of my array. I didn't want to do this with my actual data.

Thanks in advance for your thoughts!
 
Replies continue below

Recommended for you

Look up matlab 'functions"
You can create your own.
For example, your interp. could send and give back the value in one line.
[xi,yi]=interp(x,y), where interp.m is the function you created.

[peace]
Fe
 
You might like to consider the implications of "assignin".

Alternatively the following bit of code shows me asking the user to enter a search string and then copying the first variable of that name into c1. Trouble is that eval allows you to do things that are infinitely naughty.
clear
uiload;%loads a file with several arrays into workspace
who%lists them all
si=input('enter search term, with wildcards ','s');
eval (['who ',si])%lists the ones its found
s=who(si);%creates a string of the variable names

s1=char(s(1));
eval(['c1=',s1,';']); %copies that array into c1

I'm not saying the above is the correct way to do it. But it works.

So far as reading dirty files, yes there are some rather impenetrable commands that as a C++ programmer you will enjoy. Anyway read the Help on Importing and Exporting Data. Personally I make my users give me clean data, or at least structured data.



Cheers

Greg Locock


New here? Try reading these, they might help FAQ731-376
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top