matrix

Converting a matlab matrix to a vector

非 Y 不嫁゛ 提交于 2019-12-30 06:49:08
问题 I want to get a vector of elements of a Matlab matrix at predefined locations. For example, I have the following >> i = [1,2,3]; >> j = [1,3,4]; >> A = [1,2,3,4; 5,6,7,8; 9,10,11,12; 13,14,15,16] A = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 I want a vector that will give me the values of A at the locations correspongin to i,j . I tried A(i,j) ans = 1 3 4 5 7 8 9 11 12 but this is not what I wanted. I want to get the following >> [A(i(1),j(1)); A(i(2),j(2));A(i(3),j(3))] ans = 1 7 12 What is the

Matlab/Octave 1-of-K representation

一世执手 提交于 2019-12-30 06:33:09
问题 I have a y of size 5000,1 (matrix), which contains integers between 1 and 10. I want to expand those indices into a 1-of-10 vector. I.e., y contains 1,2,3... and I want it to "expand" to: 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 What is the best way to do that? I tried: Y = zeros(5000,10); Y(y) = 1; but it didn't work. It works for vectors though: if y = [2 5 7] , and Y = zeros(1,10) , then Y(y) = [0 1 0 0 1 0 1 0 0 0] . 回答1: n=5 Y = ceil(10*rand(n,1)) Yexp = zeros(n,10);

Basic matrix multiplication in OpenCV for Android

大城市里の小女人 提交于 2019-12-30 06:27:48
问题 I'm probably being incredibly stupid here but I'm having trouble doing some basicaly Mat multiplication using OpenCV for Android. I have two Mat's both of the same type, CV_64F mat1 has size: 3 rows, 3 cols mat2 has size: 3 rows, 1 cols I want to multiply them to give the product mat3 of size 3 rows, 1 cols. I've tried using: Mat mat3 = new Mat(3, 1, CvType.CV_64F); Core.multiply(mat1, mat2, mat3); But I get an error: CvException [org.opencv.core.CvException:/home/andreyk/OpenCV2/trunk/opencv

OpenCV imwrite saving complete black jpeg

若如初见. 提交于 2019-12-30 06:15:07
问题 I have done some pre processing for dft , and i am trying to save this image by imwrite. My cropped image has this information output.type() 5 output.channels() 1 output.depth() 5 But everytime when i save it gives black output. I have checked old existing threads of stackoverflow but all seems not working for me. e.g. OpenCV2.3 imwrite saves black image I have tried many color conversions and depth conversion as well but i dont know why it does not work. std::vector<int> qualityType;

Print a matrix without row and column indices

霸气de小男生 提交于 2019-12-30 06:10:09
问题 If I print a matrix, it is shown with row and column indices in the console. E.g. > print(diag(3)) [,1] [,2] [,3] [1,] 1 0 0 [2,] 0 1 0 [3,] 0 0 1 How can I suppress the column and row indices? I.e. something like this: > print(diag(3), indices=FALSE) 1 0 0 0 1 0 0 0 1 I can see that the cwhmisc package should contain a printM function to do this according to the documentation but it is not there when I load cwhmisc. Also, this seems like something you should be able to to in base R. 回答1: The

Print a matrix without row and column indices

北慕城南 提交于 2019-12-30 06:10:03
问题 If I print a matrix, it is shown with row and column indices in the console. E.g. > print(diag(3)) [,1] [,2] [,3] [1,] 1 0 0 [2,] 0 1 0 [3,] 0 0 1 How can I suppress the column and row indices? I.e. something like this: > print(diag(3), indices=FALSE) 1 0 0 0 1 0 0 0 1 I can see that the cwhmisc package should contain a printM function to do this according to the documentation but it is not there when I load cwhmisc. Also, this seems like something you should be able to to in base R. 回答1: The

What's a good C++ library for matrix operations

你说的曾经没有我的故事 提交于 2019-12-30 06:01:29
问题 I need to do multiplication on matrices. I'm looking for a library that can do it fast. I'm using the Visual C++ 2008 compiler and I have a core i7 860 so if the library is optimized for my configuration it's perfect. 回答1: FWIW, Eigen 3 uses threads (OpenMP) for matrix products (in reply to above statement about Eigen not using threads). 回答2: BLAS is a de facto Fortran standard for all basic linear algebra operations (essentially multiplications of matrices and vectors). There are numerous

R cluster with Tanimoto/Jaccard

不羁的心 提交于 2019-12-30 05:35:06
问题 Input file is Mydata <- read.table(con <- textConnection(' gene treatment1 treatment2 treatment3 aaa 1 0 1 bbb 1 1 1 ccc 0 0 0 eee 0 1 0 '), header=TRUE) close(con) Mydata is gene treatment1 treatment2 treatment3 1 aaa 1 0 1 2 bbb 1 1 1 3 ccc 0 0 0 4 eee 0 1 0 In order to built cluster, I have done d <- dist(mydata, method = "euclidean") fit <- hclust(d, method="ward") plot(fit) I got the cluster based on "euclidean" distance. In my previous message in stackoverflow How to use R to compute

Using interp2 in Matlab with NaN inputs

自闭症网瘾萝莉.ら 提交于 2019-12-30 05:29:06
问题 I have some observational data that is relatively complete, but contains some NaN values, in an matrix in matlab and I want to interpolate them to a more evenly spaced grid using interp2 So, to keep things simple lets say I have one complete (no NaN values) matrix, and one that looks something like: A = [ 1 2 3 4; 2 3 2 NaN; 0 2 3 4; 0 NaN 4 5 ] with B and C being complete matrices, interp2 won't accept an input matrix with NaN values. So if I do something like this: [AI,BI] = meshgrid(a,b) %

Matlab vs Python: Reshape

元气小坏坏 提交于 2019-12-30 02:45:11
问题 So I found this: When converting MATLAB code it might be necessary to first reshape a matrix to a linear sequence, perform some indexing operations and then reshape back. As reshape (usually) produces views onto the same storage, it should be possible to do this fairly efficiently. Note that the scan order used by reshape in Numpy defaults to the 'C' order, whereas MATLAB uses the Fortran order. If you are simply converting to a linear sequence and back this doesn't matter. But if you are