matrix

Multiplying complex matrices in Matlab

六眼飞鱼酱① 提交于 2020-01-07 09:23:10
问题 I'm trying to port a code from matlab to C. In order to convert this line to C: A = E*[SOLS' ; ones(1,10 ) ]; Where, >>size(SOLS) ans = 10 3 and: >> size(E) ans = 9 4 SOLS is a complex single matrix and E is a real single matrix and A should be a complex single matrix of size 9x10. I replaced A = E*[SOLS' ; ones(1,10 ) ]; with for i=1:9 for j=1:10 A1(i,j)=E(i,1)*SOLS(j,1))+E(i,2)*SOLS(j,2))+E(i,3)*SOLS(j,3))+E(i,4); end end The complex resultant matrix elements have the same real part as A

Multiplying complex matrices in Matlab

霸气de小男生 提交于 2020-01-07 09:22:21
问题 I'm trying to port a code from matlab to C. In order to convert this line to C: A = E*[SOLS' ; ones(1,10 ) ]; Where, >>size(SOLS) ans = 10 3 and: >> size(E) ans = 9 4 SOLS is a complex single matrix and E is a real single matrix and A should be a complex single matrix of size 9x10. I replaced A = E*[SOLS' ; ones(1,10 ) ]; with for i=1:9 for j=1:10 A1(i,j)=E(i,1)*SOLS(j,1))+E(i,2)*SOLS(j,2))+E(i,3)*SOLS(j,3))+E(i,4); end end The complex resultant matrix elements have the same real part as A

Find ranges in Matrix

╄→гoц情女王★ 提交于 2020-01-07 08:33:40
问题 There is a vector of numbers like c(3,10,24,29,37)->k and a table c(1,3)->l1 c(9,12)->l2 c(24,27)->l3 rbind(l1,l2)->ll rbind(ll,l3)->l3 [,1] [,2] l1 1 3 l2 9 12 l3 24 27 how can I find which of the numbers in the vector are in the range of the table. Here the result would be 3,24 and 10. Maybe just the indices of these numbers... 回答1: You can try sapply with any and the conditional statements: indx <- sapply(k, function(x) any(x >= l3[,1] & x <= l3[,2])) k[indx] [1] 3 10 24 来源: https:/

Adding a new column in a matrix in R

孤街醉人 提交于 2020-01-07 06:59:09
问题 I have a matrix with 1 column: > Control_Title_name vehicle_scan_id4 153 "CL2004060801AA" 155 "CL2004060801AA" 232 "EC2004102602AA" I want to add a new column (named "Class") like below: > Control_Title_name vehicle_scan_id4 Class 153 "CL2004060801AA" "Control" 155 "CL2004060801AA" "Control" 232 "EC2004102602AA" "Control" The length of first column ("vehicle_scan_id4") is variable so I want the "Control" appear in each row as a value in second column ("Class"). 回答1: You can use cbind() for

Matrix columns permutation with cublas

别等时光非礼了梦想. 提交于 2020-01-07 03:51:48
问题 I have an input matrix A of size 10x20 , I want to permute its columns as follows: p=[1 4 2 3 5 11 7 13 6 12 8 14 17 9 15 18 10 16 19 20] ;%rearrange the columns of A A=A(:,p); To do so, I constructed a permutation matrix I corresponding to the permutation vector p and permuted A can be obtained by performing the following multiplication: A=A*I I tested the permutation in Matlab and everything is ok. Now, I want to test it in cuda using cublas. The input matrix A is entered in column major.

reshape2 melt not producing all pairs

牧云@^-^@ 提交于 2020-01-07 03:48:04
问题 I have a 332 x 332 distance matrix with distances between all possible pairs of stations. I need to transform this matrix into a data.frame with three columns - start.id, end.id, and distance. I have tried the melt function from the reshape2 package but this is not giving the right result Here is a snippet of the data mat 72 79 82 83 116 119 120 127 128 137 143 144 146 147 150 151 152 153 157 160 161 72 NA 6.43 7.458 11.546 3.784 10.252 12.780 4.835 5.230 2.168 10.614 9.806 7.058 6.533 7.117

Understanding the ModelView Matrix

天涯浪子 提交于 2020-01-07 03:45:07
问题 I want to analyze the each component of my 4*4 ModelView Matrix. I came to know that the starting 3*3 of ModelView Matrix stores rotation. If i want my object to have no rotation with respect to camer a so My ModelView Matrix looks like this How to change my ModelView Matrix if i want to have NO Translation or Scaling ? Can anyone explain the Maths behind this. 回答1: The upper left 3×3 defines the base vectors of a coordinate system. It's not just rotation but also scaling, shearing and

How to structure a cell to store values in a specific format in Matlab?

ε祈祈猫儿з 提交于 2020-01-07 02:44:07
问题 I have a code that looks for the best combination between two arrays that are less than a specific value. The code only uses one value from each row of array B at a time. B = 1 2 3 10 20 30 100 200 300 1000 2000 3000 and the code i'm using is : B=[1 2 3; 10 20 30 ; 100 200 300 ; 1000 2000 3000]; A=[100; 500; 300 ; 425]; SA = sum(A); V={}; % number of rows for cell V = num of combinations -- column = 1 n = 1; for k = 1:length(B) for idx = nchoosek(1:numel(B), k)' rows = mod(idx, length(B)); if

locating a point in a 2d image that was warped

依然范特西╮ 提交于 2020-01-07 00:58:28
问题 I have an original image that has been "warped". Can someone help me with the math to calculate where a given point from the original image would show up in the warped one? I have an image with a rectangle inside of it. I know where, in the flat image the points A, B, C, D, E and F are. +------------------------------------------------+ | | | A B | | +-------------------+ | | | | | | | •F | | | | | | | | | | | | | | | | •E | | | +-------------------+ | | C D | | | +---------------------------

How to add up numbers with same value in matlab

邮差的信 提交于 2020-01-07 00:45:12
问题 So if i have an number array: a b 1 2.5 1 1.2 3 2.5 4 0.4 6 3 3 1.2 i want to sum up numbers in column a with same value of of b in column 2, like this: a b 4 2.5 4 1.2 4 0.4 6 3 so as you can see 1 and 3 add up and became 4, because they have the same value of b which is 2 and also to the rest of the numbers, so how i will do that? thanks (PS: my real data is combination of integers and decimal no. thanks) 回答1: Assuming A to be the input array, you have two approaches to play with here.