Is there a way to prompt for multiple file select and assign those files (and paths) to a variable? - matlab

Is there a way to prompt for multiple file select and assign those files (and paths) to a variable? For example, bring up a dialogue box that starts you in a base directory, and then allows you to assign files you select to different variables? Currently I have the paths and files hard coded in but this doesnt allow for any variety in the end. The other method i was using was using 24 instances of uigetfile, but this was tedious and time consuming so i swapped back to using hard coded file names.

Reread the uitgetfile documentation, there is an option to allow multiselect files:
[FileName,PathName,FilterIndex] = uigetfile(...,'MultiSelect',selectmode) opens the dialog in multiselect mode. Valid values for selectmode are 'on' and 'off' (the default, which allows single selection only). If 'MultiSelect' is 'on' and you select more than one file in the dialog box, then FileName is a cell array of strings. Each array element contains the name of a selected file. Filenames in the cell array are sorted in the order your platform uses. Because multiple selections are always in the same folder, PathName is always a string identifying a single folder.

Related

How do you copy using multi-select from Windows.Forms.OpenDialog in PowerShell using folder.copyHere() method?

Nubie question ... but you've got to start somewhere.
In my powershell console, I call Windows.Forms.OpenDialog to open a GUI file picker and browse to a location on my system and multi-select files that I want to copy. I stash that list in a variable.
Next, I use browseForFolder to choose my destination folder path and stash that in a variable
I run folder.copyHere() to copy a file using the Windows default file xfer GUI.
One file at a time works.
I want to present my multi-selected filename list to folder.copyhere and have it process the list ...
Instead, I'm stuck in my ignorance using foreach($file in $list and sending that to folder.copyhere one at a time. It's unpretty.
I tried turning my list of full-path file names into an array, and feeding folder.copyhere() the $vararray - but it wouldn't copy even the first file. One at a time yes, but that's not what I want.
If I send my list to robocopy, it processes each item in order, like a champ.
But I have GUI users and they want the GUI. Ideas on how to get folder.copyhere() to accept an array of names to process?

How do I prompt the user to choose a file that will be loaded in matlab?

I want the user of a script I'm writing to be able to navigate to a file containing their data and to load the data into the workspace. For example, if a csv file contains two cells with the values 1 and 2 respectively, I want the user to simply choose this file and those two values will be assigned to a variable in the workspace.
I have looked at using:
filename = uigetfile('*.xlsx','*.csv')
But that just returns the name of the file. Perhaps I could construct a full path to where the file they choose is found, and then read it in that way (using xlsread or csvread) but I think I'm probably missing something here. It seems that there should be a more straightforward way of doing it.
I believe that you're looking for the uiopen() function. This function will:
Open dialog box for selecting files to load into workspace.
On default, this function will display in a file explorer dialog box with the filter set to all MATLABĀ® files (with file extensions *.m, *.mlx, *.mat, *.fig, *.mdl, and *.slx).
However, you can import data from data files like CSV files and spreadsheets as well. Simply select the (All Files) option for the Files of Type field.
Once you've selected the data file you're interested in, you will be prompted with another GUI object that previews the data you are about to load into MATLAB's workspace. If you're satisfied with the format of the variables presented in the preview, simply hit the green check-mark at the right-side of the tool-box ribbon in the GUI object and, huzzah, all of the data file's contents have been loaded into separate variables (named according to their respective headers).
Alternatively, though this is undeniably a longer-winded and uglier approach, if you'd like to use the filename returned from uigetfile('*.xlsx', '*.csv'), you could use the importdata() function. This will output a struct that contains each of the variables from your data file as a separate field:
[filename, pathname] = uigetfile( ...
{'*.csv;', 'CSV file (*.csv)';
'*.xlsx', 'Excel Spreadsheet file (*.xlsx)'; ...
'*.*', 'All Files (*.*)'}, 'Pick a File to Import');
full_filename = fullfile(pathname, filename);
[A, delimiterOut] = importdata(full_filename);

Word Add in VSTO - How to get multiple ranges of text copied on multi-select

I am trying to store and high-light text copied by user when he opens the word file back. When he copies one paragraph, I am able to highlight (I am storing all this copied information for e.g. range values in an XML file) but when he copies content of multiple paragraphs using Ctrl Button, I am unable to get individual range values.
Could you guys help on this?
What you are trying to do is not supported by (the current versions of) Word because programmatic access to discontiguous selection is limited. In particular, you cannot access the different ranges in that selection (you can only the last subrange).
The limitations are listed in detail in this MSDN article:
Limited programmatic access to Word discontiguous selections

Copy name of object in variable explorer

I frequently find myself examining deeply nested data in the variable explorer, e.g.:
objectName.structArray1(5).structArray2(3).structArray3(7).doubleArray(4)
In order to be descriptive, the variable names are often long. I often want to use some of the data I'm looking at in Matlab expression, composed at the command line. So I end up typing the lengthy series of variable names and indexes. Autocompletion helps, but not much, especially since my variable names share many substrings.
It would be a lifesaver if I could copy into the clipboard the entire expression corresponding to the data being examined in the variable viewer. I haven't yet found a way to do this (the most obvious way being to right-click the tab for the data being examined). So I'm not sure if this functionality exists. Can anyone confirm or deny (hopefully the former) whether this functionality exists? If it does, how is it done?
As an example, suppose you had a class file myClass.m in the current working directory:
% myClass.m
%----------
classdef myClass
properties
structArray1
end % properties
end % class
Now suppose you issued the following commands:
objectName = myClass
objectName.structArray1(5).structArray2(3).structArray3(7).doubleArray(1:3)=rand(1,3)
openvar('objectName.structArray1(5).structArray2(3).structArray3(7).doubleArray')
You are now examining a slew of data within a deeply nested data structure. Normally, the data would have been the result of computation other than the rand statement above, and I would have browsed to it manually rather than using the openvar statement above. So I would not normally have readily available the text for the expression
objectName.structArray1(5).structArray2(3).structArray3(7).doubleArray
I have to manually type it in at the command line if I want to use it in a Matlab expression for further computation. It'd be so great if I could somehow point to the tab for that data in the variable explorer and somehow have the expression for the data copied to the clipboard. That way, I can paste it to the command line.
AFTERNOTE:
If there's no way to do this, then as an alternative to manually typing in the whole expression above, is there a way to access the corresponding data object (or a copy thereof) programmatically through the variable explorer window object? This assumes, of course, that the variable explorer is itself a data object as well, through which properties can be accessed. If so, maybe it has a property (perhaps deeply nested) that represents the expression for data in the tab that currently has the focus. If so, I can write a function to retrieve the corresponding data object.
I found that if I undock a tab from the Variables editor, I can select the variable name by double-clicking the variable name in the tab.
Sorry for the ambiguity in wording, but "tab" use to mean the protrusion in the data sheet for displaying the name of the data sheet. Nowadays, "tab" means the whole data sheet. In the first sentence above, I mean the protrusion, which unfortunately doesn't have a distinct name these days (at least none of which I'm aware).
After copying and pasting the variable name from the protrusion, the tab can be docked, which seems to put it back into its original place.

How to load many images at the same time?

I have a problem loading multiple images at the same time using matlab. Could anybody me?
How about writing a small program?
'uigetdir' [http://www.mathworks.com/help/techdoc/ref/uigetdir.html] to let user to select the directory where image files are.
'dir' and determine the names of the files in that directory.
'listdlg' to create a list of files on a GUI, with 'SelectionMode' as 'multiple'
check the file extension (you can do this before #3 also to show only image files in the list.)
count (N) how many image files the user wants to load and plot ('length' of the selected filename string).
loop for N times and go through the list of filenames, and open each one with the appropriate loader function (by determining the file extension of each file before loading)
as you load the data from the files, you can plot them however you like either in a single figure or multiple.
Best,
Y.T.