Posts

Showing posts from July, 2022

Global variables in MATLAB GUI?

  I'm working with MATLAB GUI. When I'm trying to access the variable which was defined with the push button, it is not defined in the pop up menu. The variables; it should be set 'global', so it is defined in the whole program. And I can use it in any callback. Do you guys have any idea of how to make the variables 'global'?   NOTE:- Matlabsolutions.com  provide latest  MatLab Homework Help, MatLab Assignment Help  ,  Finance Assignment Help  for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.Matlab Code for B.E, B.Tech,M.E,M.Tech, Ph.D. Scholars with 100% privacy guaranteed. Get MATLAB projects with source code for your learning and research.         Answers:  Wherever a global variable is going to be accessed in your code (say, different script files, functions etc.), it should be declared as such:  global globalVariable; . Eg.:    function myGUI_OpeningFcn(hObject, eventdata, handles, varargin)

Matlab, operator A\B

  What is the result of the operation A\B, where A(1, m) and B (1, m)? In the manual it is written: A\B returns a least-squares solution to the system of equations A*x= B. So it means x = inv (A'*A)*A'*B? However, the matrix A'*A is singular... Let us suppose:    A=[1 2 3] B=[6 7 6] A\B 0 0 0 0 0 0 2.0000 2.3333 2.0000 If ve use MLS: C = inv (A'*A) singular matrix C = pinv(A'*A) 0.0051 0.0102 0.0153 0.0102 0.0204 0.0306 0.0153 0.0306 0.0459 D= C*A'*B 0.4286 0.5000 0.4286 0.8571 1.0000 0.8571 1.2857 1.5000 1.2857 So results A\B and inv (A'*A)*A'*B are different...   NOTE:- Matlabsolutions.com  provide latest  MatLab Homework Help, MatLab Assignment Help  ,  Finance Assignment Help  for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.Matlab Code for B.E, B.Tech,M.E,M.Tech, Ph.D. Scholars with 100% privacy guarante

How to mark a point in a MATLAB plot?

  I have this plot  I need to make a straight  vertical  line at a point on x axis that the  user enters  and  show the coordinates of the intersection  of that vertical line with my plot. How can this be done in MATLAB? for example:  the user enters 1020 then a straight vertical line will be drawn at 1020 that meets the plot at some point and the coordinates of that point will be shown somehow.   NOTE:- Matlabsolutions.com  provide latest  MatLab Homework Help, MatLab Assignment Help  ,  Finance Assignment Help  for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.Matlab Code for B.E, B.Tech,M.E,M.Tech, Ph.D. Scholars with 100% privacy guaranteed. Get MATLAB projects with source code for your learning and research.         Answers:  One way to do this is to use the GINPUT function to graphically select a point using the mouse. Assuming the data you plotted is stored in a variable  data , the following code should do the so

Convert cell array of cell arrays to matrix of matrices

 I can convert a cell array of matrices to matrix:    >> C={[1,1]; [2,2]; [3,3]}; >> cell2mat(C) ans =      1     1      2     2      3     3 This is OK. But, I want to convert a cell array including other cell arrays to a matrix:    >> C={{1,1}; {2,2}; {3,3}};     >> cell2mat(C) Error using cell2mat (line 53) Cannot support cell arrays containing cell arrays or objects. So, desired output is:    >> mycell2mat({{1,1}; {2,2}; {3,3}}) ans =      1     1      2     2      3     3 How to do this? Edit: I want to do same thing for multidimensional ones also:    >> mycell2mat({{1,1;1,1}; {2,2;2,2}; {3,3;3,3}}) ans(:,:,1) =      1     1      1     1 ans(:,:,2) =      2     2      2     2 ans(:,:,3) =      3     3      3     3  NOTE:- Matlabsolutions.com  provide latest  MatLab Homework Help, MatLab Assignment Help  ,  Finance Assignment Help  for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.

How can I set subplot size in MATLAB figure?

  I often need to plot 10 images together, but using this code results in small images :    img = rand(400,600); for i=1:10 subplot(2,5,i); imshow(img); title(['Image ' int2str(i)]); end As you can see, the images do not use all available space in the screen. How can I increase the size, or decrease the padding/margin between them?  Thanks for any help.   NOTE:- Matlabsolutions.com  provide latest  MatLab Homework Help, MatLab Assignment Help  ,  Finance Assignment Help  for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.Matlab Code for B.E, B.Tech,M.E,M.Tech, Ph.D. Scholars with 100% privacy guaranteed. Get MATLAB projects with source code for your learning and research.     Answers:  I don't believe there is an easy way to do it. There are two options: First, use the position part of the subplot:    >> subplot(2,5, i, [l, b, w, h]) and calculate the left, bottom, width, height. Or, get the handl

Convert MATLAB char array to string

  Starting with the MATLAB char array, A:    A(1,1) = 'A' A(1,2) = 'P' A(1,3) = 'R' A(2,1) = 'M' A(2,2) = 'A' A(2,3) = 'Y' How can this be converted to a cell of strings, B, such that:    B{1} = 'APR' B{2} = 'MAY' Edit: A is a cell and using the function cellstr gives the error    Error using cellstr (line 23) S must be 2-D. NOTE:- Matlabsolutions.com  provide latest  MatLab Homework Help, MatLab Assignment Help  ,  Finance Assignment Help  for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.Matlab Code for B.E, B.Tech,M.E,M.Tech, Ph.D. Scholars with 100% privacy guaranteed. Get MATLAB projects with source code for your learning and research.       Answers:  Use the following function: http://www.mathworks.com/help/matlab/ref/cellstr.html    >> B = cellstr(A) B = SEE COMPLETE ANSWER CLICK THE LINK        https://matlabhelpers.com/questions/convert-m

how do you do symbolic differentiation on function handle?

  Say if i define the following:    g = @(x) x/sqrt(x^2+1) How do i get the derivative function for g, which i can then use to evaluate at different points? I tried the symbolic math toolkit, and tried the following:    >> syms x >> f = x/sqrt(x^2+1) f = x/(x^2 + 1)^(1/2) >> diff(f) ans = 1/(x^2 + 1)^(1/2) - x^2/(x^2 + 1)^(3/2) However, i cannot figure out how to turn this into a function handle/evaluate at different points. However, i prefer doing differentiation on function_handle. Thank you very much!   NOTE:- Matlabsolutions.com  provide latest  MatLab Homework Help, MatLab Assignment Help  ,  Finance Assignment Help  for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.Matlab Code for B.E, B.Tech,M.E,M.Tech, Ph.D. Scholars with 100% privacy guaranteed. Get MATLAB projects with source code for your learning and research.     nswer:  You can use  matlabFunction  to convert a symbolic equation to

how to remove the gap between subplots and around [duplicate]

  I am plotting two subplots (2x1) in one figure. I would like to remove all the spacing between two subplots and remove the xlable and xlabel ticks for the top subplot too. Also, I am trying to remove all the spacing outside the subplot. I try    set(gca, 'LooseInset', get(gca,'TightInset')) But it doesn't work. Now I am removing those margins and labels manually, I have 60 figures need to be handled and doing all those manually is time consuming. Any better way to do it? Thanks. I also try the subtightplot, it helps to reduce all the margins but the xlabel and ylabel are also cut    margins=[0 0]; t = 0:0.01:10; y1 = sin(t); y2 = cos(t); h1 = subtightplot(2,1,1, margins); plot(t, y1); ystr = {'sin(x)','(dimensionless)'} hy1 = ylabel(ystr); set(gca, 'fontsize', 14); set(hy1, 'fontsize', 14); set(gca, 'XTickLabel', [],'XTick',[]) h2 = subtightplot(2,1,2,margins); plot(t, y2, 'r-o'); hx2=xlabel('frequency&#

MATLAB: Automatic resizing of GUI components/fonts

  I am having problems in trying to make my MATLAB GUIs  automatically resizeable . After exhaustively searching the web for help and lots of testing, I could not find out a solution. I have been developing a simple GUI (with MATLAB,  without using GUIDE ) in my laptop ( Screen size/resolution = 1366x768 ). A very simplified version looks like this:  When I run the same GUI in my desktop computer ( Screen size/resolution = 1920x1080 ), it shows in the following way:  The dimensions of the GUI are automatically initialized taking into account the screensize ( the code is provided in the bottom of this post ). As you can see (highlighted by the red arrows), the fonts/spacing between components do not automatically resize so that the GUI has the same aspect no matter where we run the file. Additionally, when the GUI is manually resized, some overlap of the components occurs:  The code used for this minimal working example is the following:    function resizingGUIexample() %% SET UP GUI h

Matlab: read only header line from a .csv-file

  Assume there's a myfile.csv with variable names in the first row and decimal numbers in the following ones. In Matlab I'd like to read the header line and the decimal numbers separately. So far, I've been doing the following to extract the header line:    fid = fopen('myfile.csv'); a = textscan(fid,'%s','Delimiter','\n'); b = a{1,1}; fclose(fid); c = textscan(b,'%s','Delimiter',','); d = c{1} Then, I use the csvread command to extract the numerical part of the file. But there should be a (much) easier way to do it! First, I don't want to read the whole file (as with  a = textscan(fid,'%s','Delimiter','\n'); ) to extract only the first line. Second, it looks wrong to use 7 lines of code to do it - can it be done with less? I'd be thankful for any constructive suggestions.   NOTE:- Matlabsolutions.com  provide latest  MatLab Homework Help, MatLab Assignment Help  ,  Finance Assignment H