How to remove a slash from fullfile?

11 vues (au cours des 30 derniers jours)
Wesser le 12 Sep 2022
Commenté : Hiro Yoshino le 13 Sep 2022
I want the file path for wtf to read: 'C:\Users\jessi\Desktop\HydrusMC\Simulations\MC_1\Obs_Node.out'
but with the code as scripted below renders:
How do I drop the \ between the MC_ and the 1? I couldn't find any advise from other posts on this aspect of fullfile.
wtf= fullfile('C:\\','Users','jessi','Desktop','HydrusMC','Simulations','MC_',num2str(i),'Obs_Node.out');
  1 commentaire
Stephen23 le 12 Sep 2022
This has nothing to do with FULLFILE, you can simply concatenate them together:
or use a string:

Connectez-vous pour commenter.

Réponses (2)

Hiro Yoshino
Hiro Yoshino le 12 Sep 2022
How about this?
wtf= fullfile('C:\\','Users','jessi','Desktop','HydrusMC','Simulations',("MC_"+num2str(1)),'Obs_Node.out')
wtf = "C:\\/Users/jessi/Desktop/HydrusMC/Simulations/MC_1/Obs_Node.out"
  2 commentaires
Hiro Yoshino
Hiro Yoshino le 13 Sep 2022
wtf= fullfile('C:\\','Users','jessi','Desktop','HydrusMC','Simulations',("MC_"+num2str(i)),'Obs_Node.out');
Node_conc = fopen('wtf','r'); % Open monte carlo output file in Path (i)
You should pass the content of "wtf" to the function fopen.
In this case, you are passing the character array of 'wtf'.
You can tell the difference by checking out these as follows:
ans = 'wtf'
wtf= fullfile('C:\\','Users','jessi','Desktop','HydrusMC','Simulations',("MC_"+num2str(i)),'Obs_Node.out')
wtf = "C:\\/Users/jessi/Desktop/HydrusMC/Simulations/MC_0+1i/Obs_Node.out"

Connectez-vous pour commenter.

Voss le 12 Sep 2022
Combine the 'MC_' and the i into a single argument.
Like this:
wtf= fullfile('C:\','Users','jessi','Desktop','HydrusMC','Simulations',['MC_' num2str(i)],'Obs_Node.out');
Or this:
wtf= fullfile('C:\','Users','jessi','Desktop','HydrusMC','Simulations',sprintf('MC_%d',i),'Obs_Node.out');
  1 commentaire
Wesser le 12 Sep 2022
Thank you. These worked as well as the method suggested above.

Connectez-vous pour commenter.


En savoir plus sur Marine and Underwater Vehicles dans Help Center et File Exchange




Community Treasure Hunt

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

Start Hunting!

Translated by