What on EARTH is wrong with the Matlab string representation? This is WEIRD.
Mostrar comentarios más antiguos
So Matlab uses 'single quotes like these' to represent strings.
In most programming languages, whatever you put inside a string is sacrosanct. It doesn't affect anything outside the string, because, well, it's a string! It's DATA! The language shouldn't even be looking inside the string.
NOT SO IN MATLAB.
Consider the piece of code
thisBitmap2='resp04001.bmp';
path =[bitmapDir thisBitmap2];
movieFrame(1:h,w+1:2*w,:)=im2frame(imread(path));
This piece of code, of course, works fine.
I'd expect it to work fine whatever myString contains.
NOT SO, MATLAB! The code
thisBitmap2='resp04_001.bmp';
path =[bitmapDir thisBitmap2];
movieFrame(1:h,w+1:2*w,:)=im2frame(imread(path));
...produces the error
??? Conversion to double from struct is not possible.
The underscore makes Matlab think this string is a structure!
WHAT ON EARTH?
I'd just like to know why this is seen as a justifiable design decision.
All the best, Louise
2 comentarios
Sean de Wolski
el 10 de Mzo. de 2011
what is bitmapDir ? Does it end/begin with a \ or / (OS dependent)?
Steve Eddins
el 10 de Mzo. de 2011
Putting an underscore (or a period) in a string does not make MATLAB start treating it as a structure. Based on the information you've provided so far, I'm not sure why you jumped to that conclusion. You provided only the error message text, so we don't know what line the error actually occurred on, and we don't know what all the variables contained for both times you executed the code.
Respuesta aceptada
Más respuestas (1)
Sean de Wolski
el 10 de Mzo. de 2011
First off, it wouldn't be the underscore but the . (period) since that's how struct fields are referenced.
I'm unable to replicate your problem:
myString= 'resp04_001.bmp';
imwrite(uint8(magic(5)),myString)
imread(myString)
ans =
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
1 comentario
louise
el 10 de Mzo. de 2011
Categorías
Más información sobre String Parsing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!