How to create a string array and access the elements without throwing "COMMAND must be a string scalar or character vector" error?
Show older comments
Hi, I am trying to have a command that operates on a series of different strings (specifically, different file names). Normally I would use fullfile and something with an asterisk marker to get all the files I want from a folder, but in this case, each file has a very distinct name, and if I try to use my normal method I will end up with way too many files.
I tried to pass in the file names by using a strings array [dumps=strings(fname1,fname2,fname3,fname4,fname5)], which gave me the following 5x1 string array:
"/fslgroup/compute/Al_Dataset/refilledDump/rstruct_S3_fcc_N1_1_1_Al_M99_201228.553.out"
"/fslgroup/compute/Al_Dataset/refilledDump/rstruct_S7_fcc_Nn29_n2_10_Al_M99_201228.151.out"
"/fslgroup/compute/Al_Dataset/refilledDump/rstruct_S23_fcc_Nn45_49_109_Al_M99_201228.1424.out"
"/fslgroup/compute/Al_Dataset/refilledDump/rstruct_S27b_fcc_N23_n19_1_Al_M99_210713.5462.out"
"/fslgroup/compute/Al_Dataset/refilledDump/rstruct_S197c_fcc_Nn109_n223_53_Al_M99_200714.31.out"
This array was then submitted to the following function:
function [] = plotSimBox(dumpFiles)
for i=1:length(dumpFiles)
[~,BBox,~,~]=GBMD.loadDumpFile(dumpFiles(i));
etc.
The loadDumpFile function takes in a file name as an input, so that's what it's looking for. Even though each element of this array is a string, when I try to access them in this way, I receive the error "COMMAND must be a string scalar or character vector." Here's the complete error message:
Error using GBMD.loadDumpFile (line 634)
COMMAND must be a string scalar or character vector.
Error in plotSimBox (line 7)
[~,BBox,~,~]=GBMD.loadDumpFile(dumpFiles(i));
I'm not sure if there's a better way to construct an array of strings or to access them?
Accepted Answer
More Answers (0)
Categories
Find more on String in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!