multiplying a value and create a matrix of a certain size
Show older comments
The outcome of this line
B=strcat(num2str(i),',',str3);
is B =4,1,1. I would like to multiply B and create a matrix (a column vector) with the same size as data1 (which is a 748*3 matrix) so that I could create a new matrix like newMatrix=[data1 B] later on . Thank you.
7 Comments
Jan
on 30 Jun 2018
The output is the char vector '4,1,1'. It is not meaningful to multiply a string. You want to create a column vector, with the same size as a [748 x 3] matrix?
Please post more of you code and define the inputs accurately. It is not clear if you mean numerical arrays or char matrices.
Walter Roberson
on 30 Jun 2018
Are you certain that it makes sense in your context to multiple a character vector by something?
Elaheh
on 30 Jun 2018
Elaheh
on 30 Jun 2018
Stephen23
on 30 Jun 2018
@Elaheh: it would help if you actually described the situation: what data you have and what you the ultimate goal is. Currently you are mixing up character arrays and numeric arrays in ways that make little sense. It would help us to take a step back, and look at the broader problem that you are solving.
Elaheh
on 30 Jun 2018
Edited: Image Analyst
on 30 Jun 2018
Image Analyst
on 30 Jun 2018
B is the name of a character vector and is '41,1' -- it is not a matrix, and does not have value of 'data1, 848*3'. I think your terminology is confusing everybody.
I don't know what "each piece of data" is but why do you need a new, unique name for each piece?
Please answer my questions in Walter's answer also.
Answers (1)
Walter Roberson
on 30 Jun 2018
repmat(B, size(data1, 1), 1)
However if data1 is numeric then [data1 replicated_B] is unlikely to give you what you expect.
4 Comments
Elaheh
on 30 Jun 2018
Image Analyst
on 30 Jun 2018
What values are in str3 and i?
Any why on earth, if i is already a number, and you want to multiply numbers in B by something, and then stitch it onto the right side of data (because you said "create a new matrix like newMatrix=[data1 B]") do you want B to be a string? That makes no sense at all.
Are you sure data is a double array and not a character array? Please attach it in a .mat file.
Elaheh
on 30 Jun 2018
Elaheh
on 30 Jun 2018
Categories
Find more on Matrix Indexing 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!