Can't use mtimesx, "A C/C++ compiler has not been selected"

조회 수: 8 (최근 30일)
Anton Loubman
Anton Loubman 2020년 9월 12일
편집: Anton Loubman 2020년 9월 13일
r_mat = [1,0,0; 0,0,0; 0,0,0];
dog = im2double(imread('download.jpg'));
r_dog = mtimesx(dog, r_mat);
imshow(r_dog);
I wasn't sure how to set up the mtimesx function so I just copied all the files from the download into the directory where my script is located.
I try to run the above code but I get the error "A C/C++ compiler has not been selected with mex -setup". I installed the MinGW add-on and checked that it is the selected compiler.
How do I get the function mtimesx to work?
  댓글 수: 1
Anton Loubman
Anton Loubman 2020년 9월 12일
I checked and selected the compiler using
>> mex -setup
The result is "MEX configured to use 'MinGW64 Compiler (C++)' for C++ language compilation."
The same is shown for C.

댓글을 달려면 로그인하십시오.

채택된 답변

Matt J
Matt J 2020년 9월 12일
편집: Matt J 2020년 9월 12일
Run mex- -setup from the Matlab prompt,
>> mex -setup
and select one of the available compilers.
  댓글 수: 7
Matt J
Matt J 2020년 9월 12일
편집: Matt J 2020년 9월 12일
Well it worked, sort of. For some reason it still refuses to multiply a 225x225x3 matrix by a 3x3 matrix
I can assure you that im2double has nothing to do with the problem. A 225x225x3 matrix is definitely not compatible for slice-wise multiplication with a 3x3 matrix, and I'm not sure why you think it is. It would be equivalent to trying to do this:
A=rand(225,225,3); B=rand(3,3);
for i=1:3, C(:,:,i)=A(:,:,i)*B; end %what C=mtimesx(A,B) is trying to do
If instead, you are trying to take every A(i,j,:), make it into a row vector, and pre-multiply the row vector by, then you don't need mtimesx for that. You would instead do,
C=reshape( reshape(A,[],3)*B , [225,225,3]);
Anton Loubman
Anton Loubman 2020년 9월 12일
편집: Anton Loubman 2020년 9월 13일
You're right, in my head the dimensions made sense because the left matrix ended with a 3 and the right one starts with a 3, my bad.
At any rate thanks a lot for the help.
Correction: the matrices are compatible, as confirmed by numpy in python and a for loop implementation of matrix multiplication in MATLAB. I still don't know why mtimesx didn't multiply them so I'll just use workarounds.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by