From: Javier on 15 Jul 2010 05:55 Hi guys, a real basic question I guess. But I didn't had a course on that and I'm learning on my own. I have four matrices, whose (1,1) elements are, say: YtransMatrix_0(1,1) = 0; YtransMatrix_1(1,1) = 1; YtransMatrix_2(1,1) = 2; YtransMatrix_3(1,1) = 3; I want to create one matrix with the first column being the elements before to the second power. I would like to do it in a quick form taking advantage of the index in the name of the four matrices YtransMatrix_i I tried something like: Mx(1:4,1)=pow(sprintf('YtransMatrix_%d(1,1)',0:3),2); But that's not working. I don't know how to manage an index in the variable name. Thank you very much in advance
From: Jan Simon on 15 Jul 2010 06:19 Dear Javier, > I have four matrices, whose (1,1) elements are, say: > YtransMatrix_0(1,1) = 0; > YtransMatrix_1(1,1) = 1; > YtransMatrix_2(1,1) = 2; > YtransMatrix_3(1,1) = 3; > > I want to create one matrix with the first column being the elements before to the second power. I would like to do it in a quick form taking advantage of the index in the name of the four matrices YtransMatrix_i > > I tried something like: > Mx(1:4,1)=pow(sprintf('YtransMatrix_%d(1,1)',0:3),2); > > But that's not working. I don't know how to manage an index in the variable name. Especially if you are a newby, I'd strongly recommend not to mix names of variables and data. You will go into serious troubles with this kind of programming technique. It looks much nicer and is exactly the situation, which let the designers of Matlab call their product "MATrixLAB" and not "SCAlarLAB": YtransMatrix(1,1) = 0; % Not starting at 0, but at 1. YtransMatrix(2,1) = 1; YtransMatrix(3,1) = 2; YtransMatrix(4,1) = 3; Mx = pow(YTransMatrix, 2); Arrays are the ideal method to store several values of equal type and dimension. Good luck and welcome to Matlab, Jan
From: Javier on 15 Jul 2010 06:45 "Jan Simon" <matlab.THIS_YEAR(a)nMINUSsimon.de> wrote in message <i1mnb9$9ss$1(a)fred.mathworks.com>... > Dear Javier, > > > I have four matrices, whose (1,1) elements are, say: > > YtransMatrix_0(1,1) = 0; > > YtransMatrix_1(1,1) = 1; > > YtransMatrix_2(1,1) = 2; > > YtransMatrix_3(1,1) = 3; > > > > I want to create one matrix with the first column being the elements before to the second power. I would like to do it in a quick form taking advantage of the index in the name of the four matrices YtransMatrix_i > > > > I tried something like: > > Mx(1:4,1)=pow(sprintf('YtransMatrix_%d(1,1)',0:3),2); > > > > But that's not working. I don't know how to manage an index in the variable name. > > Especially if you are a newby, I'd strongly recommend not to mix names of variables and data. You will go into serious troubles with this kind of programming technique. > It looks much nicer and is exactly the situation, which let the designers of Matlab call their product "MATrixLAB" and not "SCAlarLAB": > YtransMatrix(1,1) = 0; % Not starting at 0, but at 1. > YtransMatrix(2,1) = 1; > YtransMatrix(3,1) = 2; > YtransMatrix(4,1) = 3; > Mx = pow(YTransMatrix, 2); > > Arrays are the ideal method to store several values of equal type and dimension. > Good luck and welcome to Matlab, Jan Thak you for your answer. Problem here is that YtransMatrix_i are really 4 2x2 matrices full of data. The names YtransMatrix_0 to YtransMatrix_3 come from 4 devices named from 0 to 3. Then I want to construct another matrix Mx whose elements are functions of the elements of the YtransMatrix [in the example I showed you the first column but it will be 4x3 matrix with also coupled elements of different YtransMatrix] I know I could write the 12 Mx's elemens one by one and writing the full names of YtransMatrix but, since they have just an index difference in the name I thought it could be made in a shorter way. Did I explain me? :)
From: Rik on 15 Jul 2010 07:35 "Javier " <jagon(a)postal.uv.es> wrote in message <i1mos5$g1u$1(a)fred.mathworks.com>... > "Jan Simon" <matlab.THIS_YEAR(a)nMINUSsimon.de> wrote in message <i1mnb9$9ss$1(a)fred.mathworks.com>... > > Dear Javier, > > > > > I have four matrices, whose (1,1) elements are, say: > > > YtransMatrix_0(1,1) = 0; > > > YtransMatrix_1(1,1) = 1; > > > YtransMatrix_2(1,1) = 2; > > > YtransMatrix_3(1,1) = 3; > > > > > > I want to create one matrix with the first column being the elements before to the second power. I would like to do it in a quick form taking advantage of the index in the name of the four matrices YtransMatrix_i > > > > > > I tried something like: > > > Mx(1:4,1)=pow(sprintf('YtransMatrix_%d(1,1)',0:3),2); > > > > > > But that's not working. I don't know how to manage an index in the variable name. > > > > Especially if you are a newby, I'd strongly recommend not to mix names of variables and data. You will go into serious troubles with this kind of programming technique. > > It looks much nicer and is exactly the situation, which let the designers of Matlab call their product "MATrixLAB" and not "SCAlarLAB": > > YtransMatrix(1,1) = 0; % Not starting at 0, but at 1. > > YtransMatrix(2,1) = 1; > > YtransMatrix(3,1) = 2; > > YtransMatrix(4,1) = 3; > > Mx = pow(YTransMatrix, 2); > > > > Arrays are the ideal method to store several values of equal type and dimension. > > Good luck and welcome to Matlab, Jan > > > Thak you for your answer. > > Problem here is that YtransMatrix_i are really 4 2x2 matrices full of data. The names YtransMatrix_0 to YtransMatrix_3 come from 4 devices named from 0 to 3. > Then I want to construct another matrix Mx whose elements are functions of the elements of the YtransMatrix [in the example I showed you the first column but it will be 4x3 matrix with also coupled elements of different YtransMatrix] > > I know I could write the 12 Mx's elemens one by one and writing the full names of YtransMatrix but, since they have just an index difference in the name I thought it could be made in a shorter way. > > Did I explain me? :) Better not use the variable names to accomplish this. A much cleaner solution could be to hold the data per device in a structure: device(1).YtransMatrix = YtransMatrix_0 device(2).YtransMatrix = YtransMatrix_1 etc. and then e.g. for i=1:length(device) M(i) = device(i).yTransMatrix[1,1]; end
From: Rik on 15 Jul 2010 07:42 "Rik" <rdewijn(a)xs4all.nl> wrote in message <i1mrp9$jv2$1(a)fred.mathworks.com>... > "Javier " <jagon(a)postal.uv.es> wrote in message <i1mos5$g1u$1(a)fred.mathworks.com>... > > "Jan Simon" <matlab.THIS_YEAR(a)nMINUSsimon.de> wrote in message <i1mnb9$9ss$1(a)fred.mathworks.com>... > > > Dear Javier, > > > > > > > I have four matrices, whose (1,1) elements are, say: > > > > YtransMatrix_0(1,1) = 0; > > > > YtransMatrix_1(1,1) = 1; > > > > YtransMatrix_2(1,1) = 2; > > > > YtransMatrix_3(1,1) = 3; > > > > > > > > I want to create one matrix with the first column being the elements before to the second power. I would like to do it in a quick form taking advantage of the index in the name of the four matrices YtransMatrix_i > > > > > > > > I tried something like: > > > > Mx(1:4,1)=pow(sprintf('YtransMatrix_%d(1,1)',0:3),2); > > > > > > > > But that's not working. I don't know how to manage an index in the variable name. > > > > > > Especially if you are a newby, I'd strongly recommend not to mix names of variables and data. You will go into serious troubles with this kind of programming technique. > > > It looks much nicer and is exactly the situation, which let the designers of Matlab call their product "MATrixLAB" and not "SCAlarLAB": > > > YtransMatrix(1,1) = 0; % Not starting at 0, but at 1. > > > YtransMatrix(2,1) = 1; > > > YtransMatrix(3,1) = 2; > > > YtransMatrix(4,1) = 3; > > > Mx = pow(YTransMatrix, 2); > > > > > > Arrays are the ideal method to store several values of equal type and dimension. > > > Good luck and welcome to Matlab, Jan > > > > > > Thak you for your answer. > > > > Problem here is that YtransMatrix_i are really 4 2x2 matrices full of data. The names YtransMatrix_0 to YtransMatrix_3 come from 4 devices named from 0 to 3. > > Then I want to construct another matrix Mx whose elements are functions of the elements of the YtransMatrix [in the example I showed you the first column but it will be 4x3 matrix with also coupled elements of different YtransMatrix] > > > > I know I could write the 12 Mx's elemens one by one and writing the full names of YtransMatrix but, since they have just an index difference in the name I thought it could be made in a shorter way. > > > > Did I explain me? :) > > Better not use the variable names to accomplish this. > > A much cleaner solution could be to hold the data per device in a structure: > device(1).YtransMatrix = YtransMatrix_0 > device(2).YtransMatrix = YtransMatrix_1 etc. > > and then e.g. > for i=1:length(device) > M(i) = device(i).yTransMatrix[1,1]; > end The square brackets in the line above are of course a mistake: > for i=1:length(device) > M(i) = device(i).yTransMatrix(1,1) > end
|
Next
|
Last
Pages: 1 2 Prev: Passing a MATLAB function to a C function Next: Error using ==> mupadmex |