Efficiently delete rows based on a condition that an element is present in both matrices
I have two large matrices
B. I want a code that efficiently deletes any row which has at least one element which is the same in both matrices.
A=[1 2;3 4] B=[2 4;1 1]
A=[3 4] B=[1 1]
See also questions close to this topic
Distance from point to every side of a rectangle
As a part of a bigger Simulink project, I am supposed to simulate a li-dar. So, I have a random point inside a rectangle and I am supposed to calculate the distance from this point to the appropriate point of the rectangle, starting from 0-degrees at the positive x-axis and increasing the angle counterclockwise by 0.5 degrees. Calculate this for every i*0.5. Of course, the most basic way is to separate it in sectors and use the best possible trigonometry formula, but I am afraid this would take too much time for calculation in Matlab/Simulink. Is there a "smarter" or more efficient way of doing this?
GUI goes blank on remote desktop
I wrote a compiled MATLAB GUI that we run on a remote machine via Remote Desktop. Overall it runs fine, but sometimes the GUI will blank out many of the control objects (buttons, table, popups). It seems to happen after the screen of the client computer has been locked or after the GUI has been minimized.
If you move the mouse over the buttons, popups, or table headers, they reappear. The table cells will reappear if they are selected. The GUI hasn't crashed and still works fine, but the objects just disappear until you make them reappear again. I have only seen this happen when using remote desktop (Windows-Windows using Remote Desktop Connection).
How can I get this to stop happening? It isn't really breaking anything, but it is very annoying.
I don't know if this is an issue in the MATLAB code or with the Remote Desktop configuration, so I posted this question here. Feel free to move this to superuser if you think it's more appropriate.
Error using GA in MATLAB for nonlinear constrained optimization
I am using GA in MATLAB to minimize a convex function. I am getting the following error,
Error using constrValidate (line 59) Constraint function must return real value.
But when in the cost.m the system called "sys" is created (which is a global variable), then the constr function computes its H_\infty norm which is a real value. Still I don't understand why I am getting this error.
My codes are as follows,
Run.m clc clear close all s = [1 3 3 5 5 5 5 5 8 9 9 12 12 13]; t = [3 2 5 4 6 7 8 12 9 10 11 13 15 14]; G = graph(s, t); L = laplacian(G); L = full(L); global A B1 B2 C gamma2 A = -L; B1 = eye(size(A, 1)); B2 = eye(size(A, 1)); C = eye(size(A, 1)); gamma2 = 10000000; tau = 0.1; Ac=; bc=; Aeq=; beq=; lb=[-(pi/(2*tau))*ones(size(A, 1),1)]; ub = [pi/(2*tau)-2*degree(G)]; options = optimoptions('ga','Display','iter'); [k, fval] = ga(@cost,15,Ac,bc,Aeq,beq,lb,ub,@constr,options) cost.m function f = cost(k) global A B1 B2 C sys v = [1:size(A, 1)]; K = diag([k(v)]); Kbar = -B1*K; sys = ss(A + Kbar, B2, C, 0); f = sqrt(trace(C*gram(sys, 'c')*C')); end constr.m function [c, ceq] = constr(k) global sys gamma2 c = hinfnorm(sys) - gamma2; ceq = ; end
Any help is really appreciated.