Matlab help! Reading in a file with a variable filename

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Matlab help! Reading in a file with a variable filename
# 1  
Old 01-29-2011
Matlab help! Reading in a file with a variable filename

1. The problem statement, all variables and given/known data:
I want to read in a file, and plot the data in matlab. However, I do not like hardwiring filenames into my codes, so I always give the user the option to specify what the filename is. I am pretty inexperienced with matlab, so I have no idea how to do this!


2. Relevant commands, code, scripts, algorithms:

My algorithm is as such:

Ask for the user to specify the filename they want to open,
have the script open the specified file,
plot the data.


3. The attempts at a solution (include all code and scripts):

clear,clc;

char file [20];
file = input('What is the filename you would like to read?');

fopen file;

and

clear,clc;

file = input('~~~~')

fopen file;


4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):

Iowa State University
Ames, IA usa
Ganesh Rajagopalan
AerE 261

---------- Post updated at 10:49 PM ---------- Previous update was at 09:50 PM ----------

Actually, I discovered a "uigetfile" command, so I got that down.

However, i'm having trouble assigning those values to variables.

I've tried the following:

[a, b, c] =

and

a = filename(:,1);

How do I assign the values in each column to a matrix of values?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Non trivial file splitting, saving with variable filename

Hello, Although I have found similar questions, I could not find advice that could help with our problem. The issue: We have a few thousands text files (books). Each book has many chapters. Each chapter is identified by a cite-key. We need to split each of those book files by... (4 Replies)
Discussion started by: samask
4 Replies

2. Shell Programming and Scripting

Output of matlab as a variable for shell script

I'm running a matlab code within a shell script. This is how I do it, matlab -nodesktop -nosplash -nojvm -r "my_program;quit" This works fine. My matlab code prints out a single number, say "ans = 10" for example. I want to assign this to a variable in the shell script. I tried doing this... (18 Replies)
Discussion started by: lost.identity
18 Replies

3. Shell Programming and Scripting

reading variable value from a file

Hello, I need to read a variable value from script. Below is the scenario I am reading a value from an external file say a.txt a.txt: Jan Feb Mar I need the corresponding value of the months in in numerics such as Jan -->1, Feb-->2 etc. I have this mapping in another file... (1 Reply)
Discussion started by: aixjadoo
1 Replies

4. UNIX for Dummies Questions & Answers

Reading a variable from file

Hi, I have a situation where I need to read a variable from another file. But the problem is that the variable in the other file is starting with $. E.g. file1: $var1=out temp_ss.sh: . file1 echo "Print : $var1" It works fine if the file1 is having var1=out (note that it is... (6 Replies)
Discussion started by: shash
6 Replies

5. Shell Programming and Scripting

reading the whole line from a file into a variable

Hi, I am doing : while read line do printf "%s\n" ${line} done <datafile.txt but I am not getting each single line from the data file assigned to the variable line (but only tokens/fields at a time). I also tried while IFS= read -r lineI want the whole line assigned or read into the... (2 Replies)
Discussion started by: shri_nath
2 Replies

6. UNIX for Dummies Questions & Answers

assingn a variable a filename and then reading it in

Im trying to set a filename to a variable and then read the file in using the variable but im getting a syntax error. any ideas? #!/bin/bash function scanFile() { while read $1 do echo $filename done } file1=report.log scanFile() $file1 (3 Replies)
Discussion started by: magnia
3 Replies

7. Shell Programming and Scripting

Reading variable from file variable values

Hi, Here is the output of lpstat. I would like to read value of Queue which is(abxxxxb1)and status that is DOWN in first line. i dont care what is in second line. any one can help me.thanks Queue Dev Status Job Files User PP % Blks Cp Rnk ------- ----- ---------... (5 Replies)
Discussion started by: sagii
5 Replies

8. UNIX for Dummies Questions & Answers

get the latest file by reading the date in the filename.

Hi, I grep for a pattern in a list of files. "grep -i -l $pattern *.datx*" it may give me n number of files. say for eg, it gives me 2 files. lock_eicu_20071228_00000000.dat_20071228_05343100 lock_eicu_20080501_00000000.dat_20080501_05343900 out of these 2 files I need to get the... (7 Replies)
Discussion started by: prsshini
7 Replies

9. Shell Programming and Scripting

Piping to a file and setting filename using a variable

Hi all, I would like to send the output of a line in a ksh script to a file, but I need to name the file using a predefined variable: ls -l > $MYVAR.arc But what is the correct syntax for achieving this? I can't seem to find the correct syntax for giving the file an extension. Any... (8 Replies)
Discussion started by: mandriver
8 Replies

10. Shell Programming and Scripting

Reading a file using sh with spaces in filename

Hi I am trouble parsing through a file with spaces in the filename. I need to grab "supportIDPS/SCM/windows_install/file groups/dds.fgl" and then do a md5sum on it. I am using sh. Any help is appreciated. Here is an example of the input file: 7eedbc9f7902bf4c1878d9e571addf9a ... (4 Replies)
Discussion started by: jekl5
4 Replies
Login or Register to Ask a Question
DEBIAN-MATLAB-MEXHELPER(1)					   User Commands					DEBIAN-MATLAB-MEXHELPER(1)

NAME
debian-matlab-mexhelper - helper to build Matlab extensions on Debian SYNOPSIS
debian-matlab-mexhelper [OPTIONS] <package name> <mode> DESCRIPTION
The is a small helper that eases building and installing MEX extensions for Matlab toolbox packages in Debian binary packages. Because these packages cannot build-depend on Matlab (for obvious reasons) they need to compile their extensions at installation time using a local Matlab installation. The helper is somewhat flexible by supporting custom build, install and clean commands, as well as source and destina- tion directories. It also deals with moving extensions into library directories and automatically symlinks them into the toolbox direc- tory. There are two major modes: 'install' to build, install and symlink extensions (useful in postinst) and 'clean' to remove installed exten- sions and symlinks (useful in prerm). The command to build the extensions is invoked in the source directory. By default, this is /usr/src/matlab/<package name>, but can be overridden with the --src-dir option. Any optional 'install' (--install-cmd) and 'clean' (--clean-cmd) are invoked in the source directory too. Moreover, this helper will also take any installed extensions from a default installation path /usr/share/matlab/site/m/<package name>, move them into /usr/lib/matlab/site/<package name> and symlink back to the original location. These locations can be configured with the --m-dir and --mex-dir options respectively. Again, this step is optional and is only performed if a package actually installs extensions inot this location. OPTIONS
-h Print usage summary and option list. --help Print full help. --version Print version information and exit. --build-cmd Command to build the extensions in the source directory --install-cmd Command to install the extensions after building --clean-cmd Command to clean the source tree after installation. This is not the command that is executed in 'clean' mode. --src-dir Directory with the extension sources. This is also the directory in which build, install and clean commands get invoked. --mex-dir Target directory into which binary extensions get moved. --m-dir Target directory in which symlinks to binary extensions get created. --make Set default commands for 'build-cmd' (make), 'install-cmd' (make install DESTDIR=$m_dir) and 'clean-cmd' (make distclean) if no spe- cific command has been provided via the respective options. EXAMPLES
The following call can be used in a package's postinst script if it comes with a Matlab script 'build_matlab.m' that builds and installs its extension into the desired locations. The --src-dir option is used to point to a non-standard location of the extension sources. debian-matlab-mexhelper somepackagename install --src-dir /usr/src/dynare-matlab/mex/sources --build-cmd 'matlab -nodesktop -nodisplay -nojvm -r build_matlab' If a package installs extension sources into the standard location and builds its extensions using a Makefile that support the DESTDIR for installing the built extensions and a 'distclean' target it is sufficient to run the following. debian-matlab-mexhelper somepackagename install --make Otherwise it is also possible to fully customize all commands. debian-matlab-mexhelper difficultpackage install --build-cmd 'make -C src all toolbox MEXBIN="matlab-mex"' --install-cmd 'make -C src install && find . ! -wholename "./src" -name "*.mex?*" -print0 | xargs -0 -I {} cp -v --parent {} /usr/share/difficultpackage' --clean-cmd 'make -C src distclean tool- box-distclean && find . -name "*.mex?*" -delete' If a package uses debian-matlab-mexhelper to install extensions into the standard location it can also be used to remove all MEX extensions and created symlinks when a package is removed from a system. To achieve this simply put the following call into a package's prerm script. debian-matlab-mexhelper packagename clean AUTHOR
Written by Michael Hanke. COPYRIGHT
Copyright (C) 2010-2011 Michael Hanke <michael.hanke@gmail.com> Licensed under GNU Public License version 3 or later. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICU- LAR PURPOSE. debian-matlab-mexhelper 0.0.18 March 2012 DEBIAN-MATLAB-MEXHELPER(1)