how do you program the file path when you do not know where the person will save the matlab file you send them?
Mostra commenti meno recenti
I have a program that reads in a graphic .tiff file that I saved in the same folder as my matlab program. I have the file path set to the saved folder. When I email my matlab program and graphic file to someone to use, how do I get program to work when I do not know where they will save the files and so do not know the future file path? Here is code section:
%this is where user is shown the diagram picture
fprintf('Look at figure 1 to see your input choices: \n \n');
%read in the picture of the beam and inputs
beamPic = imread('C:\mymatlab\beam.tiff');
%the file path above needs to be changed depending where you save files
%show the beam pictures
imshow(beamPic);
6 Commenti
darova
il 15 Mag 2020
I don't understand the question. Maybe dir is what you are looking for
jessupj
il 15 Mag 2020
this question is somewhat ill-posed. what if they have multiple files named 'beam.tiff' on their filesystem? any method that works would return multiple paths, and you'd have to have a way to pick one.
shawny badanjek
il 16 Mag 2020
shawny badanjek
il 19 Mag 2020
Rik
il 19 Mag 2020
Make sure to share the tiff in the folder as your function. That way it will work the same as a floppy disk.
Walter Roberson
il 19 Mag 2020
I already answered, https://www.mathworks.com/matlabcentral/answers/525797-how-do-you-program-the-file-path-when-you-do-not-know-where-the-person-will-save-the-matlab-file-you#answer_432769
Risposte (3)
James Tursa
il 15 Mag 2020
0 voti
If you don't want to write code to search multiple directories to find the files, your code is going to have to ask the user to input the directory.
2 Commenti
shawny badanjek
il 16 Mag 2020
Rik
il 16 Mag 2020
If you send the files together it is up to the user to not separate them. So I don't really understand what feature you are asking for.
You can retrieve the path of function and see if the tiff file is in that folder. Would that solve it?
jessupj
il 15 Mag 2020
DIRS = dir('**/beam.tiff'); % gets a structured list of matching files
% ...
% additional criterion here to choose which to pick.
k=1; % assume you want the first match
beamPic = imread( [DIRS(k).folder '/beam.tiff']) % maybe
imshow(beamPic);
Walter Roberson
il 16 Mag 2020
0 voti
If sending the source code is okay, then bundle an app
You would use mfilename('fullpath') to find out the name of the .m file, and could then extract the directory part with fileparts()
If you are building a .exe then tell the application compiler to add the file to the executable, and then in the program open it without providing a path. The file will be unbundled into a temporary directory whose name you can get with ctfroot() .
Categorie
Scopri di più su File Operations in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!