How to load many images at the same time? - matlab

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.

Related

How to load .mat files onto Matlab? Basically what's wrong with my code?

For this project we have been given code, and will be changing some inputs and assumptions. Thus, I already possess the original codes, but just changing all the creator's file paths to match my own computer is yielding me a lot of trouble. The following, and many variations of, continually yield errors.
load \Users\myname\Library\Documents\...
The error is
Error using load
'Unable to read file
\Users\myname\Library\Documents...'.
No such file or directory.
My files are stored in my Documents. Another person in my group on windows has used
load C:\Users\hisname\Desktop\...
Is there something I'm missing in my line, similar to the C drive but on Mac? Is my code just completely wrong, I'm able to load files in R quite easily, but Matlab is posing a huge hurdle. I have no experience with Matlab and have been asked simply to run this code.
On the Mac, path components are separated by /, not \. Thus, you should type
load /Users/myname/Documents/filename.mat
You can use the location bar at the top of the command window to change to the directory where your file is located, and then you can type
load filename
to load filename.mat.
Also, are you sure you have a Documents directory under Library? Why?
To run code from a file called "my_file.m", than just open your Matlab and type run my_file.m. This will run your script in the Command Window.
The load function is used, if you want to load a .mat file. These are normally files, where variables from your workspace are stored.

Uploading multiple .txt files at once on MATLAB GUI

I would like some guidance on how to import multiple .txt files containing data seperated by comma on a MATLAB GUI. Once the files are uploaded, I have a function that will manipulate all the data from each .txt file.
Any help is appreciated.
The easiest way to import multiple files is to:
Use the file importer GUI in matlab and generate a script after you
selected your preferred parameters
Generate a script (there is a button to generate a script in the importer)
Modify the script with a for loop to load multiple files and save them in a variable (a cell array can handle different sizes of data in each file)
Try uigetfile to launch a dialog for loading files. Set 'MultiSelect' to 'on' in order to select multiple files at once.
Here's an example call:
[filenames, pathname] = uigetfile({'*.txt; *.csv','Comma separated values';...
'*.*','All files'},'Select files','MultiSelect','on');
You will need to check if the user actually selected a file or if they canceled.
If I understand your question correctly, you have a GUI already. In this case you just need to add the above call to your designated callback function (i.e. whatever you click to invoke this file load interface).

How to create blank .mat file from terminal?

Is there any way to create an empty .mat file from a terminal session? Basically, what I am doing is brain graph analysis. The software I am using, if an entire brain is scrubbed (ie, if the displacement of the brain is greater than a certain threshold) the output file will be left out or will be very small. When analyzing, however, I need to be able to eliminate both subjects from the analysis if the entire brain is scrubbed/too much of the brain is scrubbed. To accomplish this, the easiest way would be to simply check the dimensions of the output file within matlab, and if they are below the arbitrary threshold I decide then both subjects will just be skipped over for analysis. The issue is, I can easily check if a file contains too few remaining frames, however, if the resulting file contains no frames, it will entirely just not exist. As the outputs are all sorted, the only thing I need to do is check consecutive files' dimensions, and if one of the files does not contain enough values, then I can simply skip over it entirely. Simply touching a blank file obviously will not work, since it will not contain any encoding. I hope this is a good explanation for my motivation to do this, and if any of you know of any suggestions, please let me know.
A simple solution would be to create an empty file from Matlab and duplicate the file when needed from the console.
Just open Matlab, set to the destination folder and type this:
clear all
save empty.mat
Then, when needed, copy the file from the console. :)
Saving the contents of an empty struct creates an empty .mat file:
emptyStruct = struct;
save('myFile.mat','-struct','emptyStruct');

Matlab multiple image loading / processing

I'm trying to process 77 images on a single matlab script. I have to load these images and use several processing functions on each. The image names are not sequential. How can I do that without explicitly writing all?
Thanks in advance.
you can use dir to get a list of all the files and folders in the current folder you are in, for example
s=dir(fullfile(matlabroot, 'toolbox/matlab/audiovideo'))
returns the contents of the matlab/audiovideo folder, where s.name will contain the names of the files in that folder.
Another example:
s=dir('*.mat')
will return to s.name all the file names in the current folder that are of type .mat
Now you can load these files in a loop:
for n=1:numel(s)
load(s(n).name);
.... % do whatever
end

C# folder and subfolder

Upon numerous searches, I am here to see if someone has any idea on how I should go about tackling this issue.
I have a folder with sub-folders. The sub-folder containers each has files of different file types e.g. pdf, png, jpeg, tiff, avi and word documents.
My goal is to write a code in C# that will go into the subfolder, and combined all the files into one pdf using the name of the folder. The only exception is that a file such as avi will not be pdf'ed in which case I want a nudge as to which folder it is and possibly file name. I am trying to use the form approach, so that you can copy in the folder pathname and also destination of the created pdf.
Thanks.
to start, create a FolderBrowserDialog to get the root folder. Alternatively just make a textbox in which you paste the folder name ( less preferred since the first method gives you nicer error-handling straight out of the box )
In order to iterate through, see How to: Iterate Through a Directory Tree
To find the filetype, check System.IO.FileInfo.Extension for each file you iterate through. Add those to list with the data you need. ( hint, create a list of objects in which your object reflects the data you need such as path, type etc,... ). If its an avi don't toss it in the list but flash a warning (messagebox?) instead.
From here the original question gets fuzzy. What exactly do you need in the pdf. Just the filenames and locations or do you actually want to throw the actual contents of the file in pdf?