Borrar filtros
Borrar filtros

User Inputs String variable that is name of vector. want script to calculate on values of that vector

3 visualizaciones (últimos 30 días)
Hello,
I know this is VERY BASIC, but I cannot find an answer in the books, Matlab Guide, or Matlab Central.
Need help with a script:
workspace has a lot of named variables
Request user input:
filename = input ('select a variable', 's');
now filename is a string
the name (string) in filename is associated with a vector of some 50K numbers
I want to analyze the vector whose name is in the string filename
How can I tell Matlab to calculate on the vector?
  2 comentarios
Walter Roberson
Walter Roberson el 18 de Feb. de 2013
What file format is the file in? Or what command would you use to load one of the files by name?
Don
Don el 19 de Feb. de 2013
The original file was imported as an EDF file. BUT I read it very well, so the variable that is the subject of this question is a vector already in the workspace.
The problem: I read and open a file (the EDF file) and a whole set vectors exist in the workspace. I ask the user (essentially) "which vector do you want to analyze?"
The user might enter FileX (which is the name of a workspace vector) I want to use the string "FileX" to label the output, AND want to analyze the vector that is associated in the workspace with the name FileX.
Once the user types FileX in response to the INPUT statement, the name is either (1) a numerical array or (2) a string. I wanbt to use it both ways -- as a string to label plots and as a numeric array to analyze.
is this clearer?
please help if you can
thank you

Iniciar sesión para comentar.

Respuestas (2)

Image Analyst
Image Analyst el 18 de Feb. de 2013
Try this:
[baseFileName, folder] = uigetfile('*.*', 'Select a variable');
fullFileName = fullfile(folder, baseFileName)
Then use some code to read in "the vector" from your file. You can use a function such as csvread(), dlmread(), textscan(), fgetl(), or whatever works.
  1 comentario
Don
Don el 19 de Feb. de 2013
Thank you. please see my response the answer provided above. Surely this problem is not beyond Matlab's capability.
But it is beyond my understanding.
Many thanks

Iniciar sesión para comentar.


Walter Roberson
Walter Roberson el 19 de Feb. de 2013

Categorías

Más información sobre String Parsing en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by