I have a matrix of strings such as the following:
readFiles = [
"11221", "09";
"11222", "13";
"12821", "06";
"13521", "02";
"13522", "13";
"13711", "05";
"13921", "01";
"14521", ".001";
"15712", ".003"
];
These are used to access to some folders and files in an automatic way. Then what I want to do is the following (with ii
being some integer):
FileName = strcat('../../Datasets/hc-1/d',readFiles(ii,1),'/d',...
readFiles(ii,1),readFiles(ii,2),'.dat');
data(ii,:) = LoadBinary(FileName, 6);
The string FileName
is then generated using double quotes (I'm not sure why). So its value is:
FileName =
"../../Datasets/hc-1/d13921/d1392101.dat"
The function LoadBinary()
returns an error when trying to perform the following operation:
lastdot = strfind(FileName,'.');
FileBase = FileName(1:lastdot(end)-1); % This line
However, if I create the string FileName
manually using single quotes, the function works okay.
In a nutshell, if I try to index a string (FileName(1:lastdot(end)-1)
) that is created with the lines above (leading to FileName = "../../Datasets/hc-1/d13921/d1392101.dat"
), MATLAB returns an error. If I create it manually with single quotes (FileName = '../../Datasets/hc-1/d13921/d1392101.dat'
), the function works right.
Why does this happen? Is there a way to fix it (i.e. convert the double-quoted string into a single-quoted one)?
A single-quoted string does not have variables within it interpreted. A double-quoted string does. Also, a double-quoted string can contain apostrophes without backslashes, while a single-quoted string can contain unescaped quotation marks.
Both single (' ') and double (" ") quotes are used to represent a string in Javascript. Choosing a quoting style is up to you and there is no special semantics for one style over the other. Nevertheless, it is important to note that there is no type for a single character in javascript, everything is always a string!
As far as language syntax is concerned, there is no difference in single or double quoted string. Both representations can be used interchangeably. However, if either single or double quote is a part of the string itself, then the string must be placed in double or single quotes respectively.
Double quotes are String array, while Single one are Char array. You can convert your string array to a char one using the function char
.
So you'd write :
CharFileName = char(FileName)
And it should resolve your issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With