[Solved] Non-scalar in Uniform output error in arrayfun. How to fix?

The error message give you a big hint where to look: Undefined operator ‘+’ for input arguments of type ‘cell’. Error in gbp2/pts (line 36)                    ylist(z) = ylist(z) + arrayfun(@(coor) u(z, coor, mode, w, R,                    Psi),xlist(z).’,’uniformoutput’,false); From the documentation for arrayfun and the ‘UniformOutput’ option: Requests that the arrayfun function combine the outputs into cell … Read more

[Solved] Reading output of a function as an input in another function [closed]

The optimization algorithm that I was using was GA(Genetic Algorithm). I wrote this function in order to get what I wanted: function [zz,fvalzz] = secstep(z,NVARS) [zz,fvalzz]=ga(@secfun,NVARS); function ff = secfun(zz) y=.5*exp(-35*10^12*(t-2e-6).^2).*cos(2*pi*5e6*(t-2e-6)+0); sigme2=zz(1)* exp(-z(1)*10^12*(t-zz(2)*10^-6).^2).*cos(2*pi*z(3)*10^6*(t-zz(2)*10^-6)+z(4)); %z vector has been calculated from another function. NN=length(y); ff =sum((y-sigme2).^2)/NN; end end solved Reading output of a function as an input … Read more

[Solved] how to find the black region in near the edge

color_img = imread(‘0k4Kh.jpg’); img = rgb2gray(color_img); [x, y] = size(img); for i = 1:x if length(find(img(i, :))) ~= 0 lastmarginalrow = i-1; break; end end for ii = y:-1:1 if length(find(img(:, ii))) ~= 0 lastmarginalcol = ii-1; break; end end figure; fig = imshow(color_img); h = impoly(gca, [0,x; lastmarginalcol,x; lastmarginalcol,lastmarginalrow; 0,lastmarginalrow]); api = iptgetapi(h); api.setColor(‘red’); … Read more

[Solved] Writing a function that calculates sine for inputted number of terms. MATLAB [closed]

found the answer myself.. note that there is a difference between sinx and sin(x) function [sinx, error] = sinx_approx(x) % approximates the value of sin(x), the approximation is more accurate as % the number of terms selected is increased. n= input(‘Up to how many terms would you like to evaluate?’); sinx=0; for i=1:1:n sinx=(-1)^(i+1) * … Read more

[Solved] Total Number of pixels in an image [closed]

The total number of pixels is not equal to the sum of values in your image. sumOfAllPixelValues = sum(double(rgbImage(:))); numberOfPixels = numel(rgbImage); The size on disk of an image is numberOfPixels*bytesPerPixel, where bytesPerPixel depends on the bit depth of an image (uint8 would be 8 bits=1 byte, for example. To downsample the image by half, … Read more

[Solved] How to do imagesc and axis off at the same time in Matlab? [closed]

It’s not possible to do imagesc and axis off at the same time. However, you can modify the imagesc code to achieve this but you will not get MathWorks support for the modified version. To avoid the graphical artifacts, try different figure renderers: painters, opengl, … You can also try the startup flag -softwareopengl. solved … Read more

[Solved] Create a larger matrix in special case [closed]

I’m assuming that A and B are coordinates, and you want to “draw” the plot in matrix form, so try this: c = flipud(full(sparse(B, A, B))); I added flipud to adjust the positive direction of the y-axis upwards. Alternatively, you can obtain a binary matrix using this: c1 = flipud(full(sparse(B, A, ones(size(A))))); Important: for this … Read more

[Solved] can anyone suggest to me LARS algorithm code? [closed]

make some arrays of data: n=100 v1=rand(n,1); v2=rand(n,1); v3=rand(n,1); make a linear combination of the data Y=2*v1+3*v2+5*v3; make a noisy matrix out of the data: X=[v1 v2 v3]; X=X+rand(size(X))/10; run the function beta=lars(X, Y) beta should be [2,3,5] solved can anyone suggest to me LARS algorithm code? [closed]

[Solved] Coordinate system transformation, 3d projection to 2d plane

The problem can be expressed as finding the 3-by-3 matrix M such that the coordinates of a point P can be converted between the old coordinate system (P_old, 3 rows) and the new coordinate system (P_new, 3 rows). This is an affine transformation: P_old = Center + M * P_new (1) The (matrix-vector) multiplication with … Read more