changing char to string(?)
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
MADISON RAGONE
el 10 de Dic. de 2021
Comentada: MADISON RAGONE
el 10 de Dic. de 2021
I am currently trying to make a simple code named subjex.dat
The goal is to create a 5x2 matrix with these values that will pop up
5.3 a
2.2 b
3.3 a
4.4 a
1.1 b
What i have so far is
a = 'a';
b = 'b';
matrix1 = [5.3, 2.2, 3.3, 4.4, 1.1]'
matrix2 = [a,b,a,a,b]'
matrix3 = [matrix1,matrix2]
How do I get the numbers to show? Right now, all this I see is "5x2 char array" and then the letters
0 comentarios
Respuesta aceptada
Walter Roberson
el 10 de Dic. de 2021
a = 'a';
b = 'b';
matrix1 = [5.3, 2.2, 3.3, 4.4, 1.1]'
matrix2 = [a,b,a,a,b]'
matrix3 = table(matrix1,matrix2)
writetable(matrix3, 'subject.dat', 'filetype', 'text', 'writevariablename', false, 'delimiter', 'tab')
type subject.dat
3 comentarios
Walter Roberson
el 10 de Dic. de 2021
Perhaps your actual code is doing something different than the test code. The output in matrix3 is, like the output says, a 5 x 2 table object, not a cell.
The code I showed works even if matrix2 is a cell array of character vectors.
a = 'apple';
b = 'ball';
matrix1 = [5.3, 2.2, 3.3, 4.4, 1.1]'
matrix2 = {a,b,a,a,b}'
matrix3 = table(matrix1,matrix2)
writetable(matrix3, 'subject.dat', 'filetype', 'text', 'writevariablename', false, 'delimiter', 'tab')
type subject.dat
Más respuestas (0)
Ver también
Categorías
Más información sobre Characters and Strings en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!