Adding two strings same row size

2 visualizaciones (últimos 30 días)
Bastiaan Pierik
Bastiaan Pierik el 24 de En. de 2021
Comentada: Stephen23 el 27 de En. de 2021
First string presents the name of the sensors to be measured: And are separated by semicolons.
str='TC1;TC2;TC3;TC4;C1;C2;C3;C4'
Second string are 8 rows separated by str2= randi([-10,80],20,8)
I had some problems with rand and tells me the rand can’t produce a scalar,
Second problem is adding both both columns with the same length on top of each other
I would like to use join,I get the following error I don’t understand. I am running this on Matlab mobile.
totalstr=join(output_str,str2,'delimiter') Error using join (line 73) Dimension argument must be a positive integer scalar within indexing range.
  1 comentario
Stephen23
Stephen23 el 27 de En. de 2021
Bastiaan Pierik's incorrectly posted and accepted "answer" moved here:
Many thanks for all the replies! So there are two methods to do this.

Iniciar sesión para comentar.

Respuestas (2)

Star Strider
Star Strider el 24 de En. de 2021
To use the join function, your data must first be present as table objects.
Fortunately, that is not necessary. Just use array2table:
str={'TC1','TC2','TC3','TC4','1','C2','C3','C4'};
str2= randi([-10,80],20,8);
T = array2table(str2, 'VariableNames',str);
That should do what you want.
  4 comentarios
Bastiaan Pierik
Bastiaan Pierik el 25 de En. de 2021
Ok, that’s nice to know, I thought I had to make a another array and join them together like with outerjoin, I am getting errors I doing this. The first two inputs must be tables
Star Strider
Star Strider el 25 de En. de 2021
Thank you!
It is only possible to join table objects, at least using that function.
(Note — There are several join functions, such as the one I refer to in this sentence that applies to string arrays. The functions themselves determine what version of the function to use, depending on the arguments provided.)

Iniciar sesión para comentar.


Cris LaPierre
Cris LaPierre el 24 de En. de 2021
What are you trying to create?
The issue is you are mixing data types in an array. I think the way would do this is to use a table.
output_str={'TC1' 'TC2' 'TC3' 'TC4' 'C1' 'C2' 'C3' 'C4'};
str2= randi([-10,80],20,8);
totalstr = array2table(str2,'VariableNames',output_str)
totalstr = 20x8 table
TC1 TC2 TC3 TC4 C1 C2 C3 C4 ___ ___ ___ ___ ___ ___ ___ ___ 46 55 -9 62 55 -2 72 15 16 79 20 48 16 22 1 -10 46 6 59 63 47 -1 31 15 52 50 42 -5 -8 43 79 67 -9 2 23 78 -10 62 -10 73 62 1 39 76 -4 -2 37 21 0 74 16 -3 1 76 50 18 50 33 6 10 56 64 20 58 40 22 26 -8 11 68 43 29 5 13 31 46 -6 19 5 50 0 8 47 5 53 18 0 45 0 4 0 2 59 57 18 -10 54 20 73 44 -6 31 30 55 15 28 9 50 68 -10 -8 53 5 68 33 79 46 65 77 71 20 -4 65 27 -7 23 48 76
  7 comentarios
Bastiaan Pierik
Bastiaan Pierik el 25 de En. de 2021
Hi Cris,
What I am trying to do is to get a substitute for understanding reading out my arduino directly and the data from a txt file. To do so I have to create a substitute table that resembles the data I am collecting from my microprocessor. I am working from my cellphone because I am not connected to the Matlabserver at the moment. Second part is iPhones don’t have access to files that are readout on the directory, third the buffer in Matlab isn’t to big handling large quantities of data.
What I would like to do is read out the uC
TC1;TC2;TC3;TC4;C1;C2;C3;C4' Separated by ;
Below the each temperature and current sensor I have the variables from my arduino
Like:
46 55 -9 62 55 -2 72 15 16 79 20 48 16 22 1 -10 46 6 59 63 47 -1 31 15 52 50 42 -5 -8 43 79 67 -9 2 23 78 -10 62 -10 73 62 1 39 76 -4 -2 37 21 0 74 16 -3 1 76 50 18 50 33 6 10 56 64 20 58 40 22 26 -8 11 68 43 29 5 13 31 46 -6 12 36 48
Do I have to convert the variables first to a str2double? and separate the temperatures on ; or white space?
In generell is a txt file a string or how does Matlab know it is a double?
Thanks for your time and reading this:)
I would like to do some data recording and compare measurements with theory
Cris LaPierre
Cris LaPierre el 25 de En. de 2021
Share an example of the text file you are trying to read. Note that I am using my laptop with the full version of MATLAB, not MATLAB Mobile.

Iniciar sesión para comentar.

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by