https://kr.mathworks.com/matlabcentral/answers/questionsMATLAB Answers — 새 질문2019-10-16T21:46:18Ztag:kr.mathworks.com,2005:Question/4856192019-10-16T07:51:38Z2019-10-16T21:46:18ZE) Design a well-packaged MATLAB program, with user-friendly interface for the following game: [20 Marks] (i) Two players, A and B, play a game called Lotto by Two Players. The Lotto machine generates a random lotto number in the range 0-50. They takDesign a well-packaged MATLAB program, with user-friendly interface for the following game: [20 Marks] (i) Two players, A and B, play a game called Lotto by Two Players. The Lotto machine generates a random lotto number in the range 0-50. They take turns choosing any number, positive or negative to build-up their total to the lotto number. Player A starts and may choose any number. After each move, the number chosen is added to a common running total. If the total exceeds the lotto number, a message indicating that the total is too high should be displayed, similarly the opposite if the number is too low. For example, a random lotto number of 45 is generated (hidden). A starts with 25(total=25), the script now displays that the total is too low. B then chooses 25(total=50). The script now says the total is too high. A chooses -10 (total 40), and so forth. Write a script file to simulate the game that allows each player to correct the total 20 times. If there is no matching total after 20 chances for each player, the player whose previous guess brought the total closest to the lotto number wins, otherwise they share the lotto winnings( if both equally closer).MHLAWAKHE VATSHAhttps://kr.mathworks.com/matlabcentral/profile/authors/14886671-mhlawakhe-vatshatag:kr.mathworks.com,2005:Question/4857612019-10-16T21:44:26Z2019-10-16T21:44:26ZFind intersection of 2 normal distributionHi,
I have 2 normal pdf and I want to find their intersection:
the intersection is between 160 to 170.
I have code as follows:
mu1 = 160;
var1 = 20;
mu2 = 175;
var2 = 15;
yfun = @(mu,var, x)(2*pi*(var))^(-0.5)* exp(-((x-mu).^2)/(2*(var)));
val = fzero(@(x) yfun(mu1, var1, x) == yfun(mu2, var2, x), rand * (mu1 - mu2) + (mu1 + mu2))
Output:
val =
324.6802
Its the value of 2nd parameter of fzero() and fzero() sets val to it's 2nd parameter whatever i change it to.
How do i find the intersection's x value?Aishwarya Radhakrishnanhttps://kr.mathworks.com/matlabcentral/profile/authors/12911762-aishwarya-radhakrishnantag:kr.mathworks.com,2005:Question/4857602019-10-16T21:36:36Z2019-10-16T21:36:36ZTrouble running glmnet in Matlab R2019b on Mac Os Catalina 10.15Has anybody else encountered problems using the glmnet package on Mac Os Catalina 10.15? I am using Matlab R2019b.
I downloaded the package and saved all files within my working directory. When I try to invoke the glmnet function, I get the following error:
Invalid MEX-file
'/Users/name/Desktop/glmnet_matlab/glmnetMex.mexmaci64':
dlopen(/Users/name/Desktop/glmnet_matlab/glmnetMex.mexmaci64, 6): no
suitable image found. Did find:
/Users/name/Desktop/glmnet_matlab/glmnetMex.mexmaci64: code
signature in
(/Users/name/Desktop/glmnet_matlab/glmnetMex.mexmaci64) not
valid for use in process using Library Validation: library load
disallowed by system policy
I also get an error if I go into my working folder and try to open up the file in question ( glmnetMex.mexmaci64 ) with Matlab. When I do this, I get a pop-up error window saying
Error using Open. Cannot edit the Mex- file.
Any thoughts on how to get around this? Any help is much appreciated.
Thanks,
Mick
Michael Powerhttps://kr.mathworks.com/matlabcentral/profile/authors/2397993-michael-powertag:kr.mathworks.com,2005:Question/4857592019-10-16T21:35:34Z2019-10-16T21:35:34ZSome insight on mvnrnd functionHi, I am trying to simulate a simple bivariate VAR(1) process with Gaussian errors and I use mvnrnd function to draw from a multivariate normal with mean [0;0] and variance matrix .
I was creating my errors outside of my for loop, but I realised the two approaches below give completely different results:
mu = [0;0]; sgm = [1 0.7; 0.7 1]; iter = 100;
rng(1)
E = mvnrnd(mu, sgm, iter);
E_e = zeros(iter,2);
rng(1)
for i = 1:iter
E_e(i,:) = mvnrnd(mu, sgm);
end
Can you give me some insight on why these two are different - I have some ideas but cannot formalise my thoughts. Ezgi Kurthttps://kr.mathworks.com/matlabcentral/profile/authors/11674197-ezgi-kurttag:kr.mathworks.com,2005:Question/4847892019-10-11T13:42:01Z2019-10-16T21:35:00ZNew to matlab. Trying to code with excel.I am new to matlab and I am trying to read an excel file. This is what I need it to read. Each column will be a seperate name listed in the first row. Below each column has a "1" extending for x amount of rows. I am trying to store the number of those "1's" as the amount under each column/name. I am trying to loop this so that i can have multiple columns if necessary.
Basically this,
Name1 Name2.............(etc).....
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1
1
1
1
1Aris Desaihttps://kr.mathworks.com/matlabcentral/profile/authors/16224932-aris-desaitag:kr.mathworks.com,2005:Question/4857542019-10-16T20:53:42Z2019-10-16T21:32:01ZError with write accessBelow is my code. I am trying to gain write access, and am confused why all of a sudden I am not getting access, as I have saved to 'D:' just fine previously. It is not a space issue for a fact. Any help with how to gain write access would be great! I already went into properties and made sure I had admin rights and all that. I also ran Matlab as an admin as well but same error. Much thanks in advance!!
I'm operating on a Windows 10 pro and am using Matlab R2019a.
ERROR MESSAGE:
>> anovan_analysis
Error using aft_SaveAs (line 132)
Error saving file D:/SAMP/Variability_Project/Code/Creating_MDMsGLMs/3X3X3_3maps.vmp: Error moving file
'D:\SAMP\Variability_Project\Code\Creating_MDMsGLMs\Brodmann-Area-01\anova_effect.vmp.tmp' to
'D:\SAMP\Variability_Project\Code\Creating_MDMsGLMs\Brodmann-Area-01\anova_effect.vmp': Cannot write to
destination: D:\SAMP\Variability_Project\Code\Creating_MDMsGLMs\Brodmann-Area-01\anova_effect.vmp. Use
the 'f' option to override...
Error in xff/subsref (line 159)
[varargout{1}] = feval(tfm{6}, xo, fargs{:});
Error in anovan_analysis (line 152)
f_Map.SaveAs('anova_effect.vmp');
MY CODE:
%% Grab Data
%Enter the Brodmann areas you are testing here
areas = ["01","02","03","04","05","06","07","08","09","10","11","12","13","17","18","19"...
,"20","21","22","23","24","25","27","28","29","30","31","32","33","34","35"...
,"36","37","38","39","40","41","42","43","44","45","46","47"];
name = 'D:\SAMP\Variability_Project\Code\Creating_MDMsGLMs\Brodmann-Area-';
%This forloop loops through all the Brodmann area glms in their respective
%folders
for i = 1
new_name = strcat(name, areas(i));
cd (new_name)
%rps = findfiles([], pwd);
% upload MDM
glmfiles = dir('*.glm');
glm = xff(glmfiles.name);
% % I want to get this code to loop through all the Brodmann areas without me
% % having to manually input it every time
% test = xff('Brodmann_17.glm');
%These are collecting the blind and sighted maps from the PhD group. There
%are 13 blind subjects and 18 sighted subjects
num_subj_bl = 13;
num_subj_si = 18;
blind = glm.GLMData.BetaMaps(:,:,:,26:38);
sighted = glm.GLMData.BetaMaps(:,:,:,39:56);
[Dim1, Dim2, Dim3, Dim4] = size(glm.GLMData.BetaMaps);
%These are collecting the blind and sighted maps from the rainbow group.
%There are 12 blind subjects and 13 sighted subjects
num_subj_bl1 = 12;
num_subj_si1 = 13;
blind1 = glm.GLMData.BetaMaps(:,:,:,1:12);
sighted1 = glm.GLMData.BetaMaps(:,:,:,13:25);
%% Preparing for forloop
%Concatenating the blind and sighted subjects
blind_all = cat(4,blind,blind1);
sighted_all = cat(4,sighted,sighted1);
fmap_vis = zeros(58, 40, 46);
fmap_cohort = zeros(58, 40 ,46);
fmap_int = zeros(58, 40 ,46);
total_subj_bl = 25;
total_subj_si = 31;
%These are the creating the appropriate strings necessary for anovan analysis
str1 = [string('Blind')];
str2 = [string('Sighted')];
str3 = [string('Rainbow')];
str4 = [string('PhD')];
%string for factor 1, blind v sighted
vision = [repmat(str1,1,25), repmat(str2,1,31)];
g2 = [repmat(str4,1,13), repmat(str3,1,12)];
g3 = [repmat(str4,1,18), repmat(str3,1,13)];
%string for factor 2, rainbow vs PhD cohort
cohort = [g2 g3];
%% This forloop will loop through all the voxels
for a= 25
for b= 25
for c= 25
%These first 3 forloops loop through each unique voxel in the 175 x 121 X
%139 3D matrix that is generated for each subject
%These forloops loop through each individual subject in the blind and
%sighted conditions and put the corresponding voxels across all the
%subjects in a column vector. Therefore, voxel (1,1,1) across all 12 blind
%subjects will be put in the vector blind_vox and voxel (1,1,1) across all
%13 sighted subjects will be put in the vector sighted_vox.
blind_vox = [];
sighted_vox = [];
for x= 1:total_subj_bl
vox = blind_all(a,b,c,x);
blind_vox = [blind_vox; vox];
end
for y= 1:total_subj_si
vox1= sighted_all(a,b,c,y);
sighted_vox = [sighted_vox; vox1];
end
%This is creating a response vector for anovan analysis
data_all = vertcat(blind_vox, sighted_vox);
%Running a 2x2 ANOVA on the data using anovan
[p, tbl] = anovan(data_all,{vision cohort},'model','interaction','varnames',{'vision','cohort'},'display','off');
%Saving the f stats for the main effects and interaction
%This is the F stat for blind v sighted
fstat_vis = tbl(2,6);
fstat1 = cell2mat(fstat_vis);
%This is the F stat for cohort type, rainbow vs. PhD
fstat_cohort = tbl(3,6);
fstat2 = cell2mat(fstat_cohort);
%This is the F stat for the interaction
fstat_int = tbl(4,6);
fstat3 = cell2mat(fstat_int);
%Padcat takes the uneven column vectors since they both have a
%different number of subjects and turns them into even column
%vectors by padding the smaller vector with NaN values
%vect_for_BF = padcat(blind_vox, sighted_vox);
%This runs the Brown Forsythe test on the 2 column matrix
%[p,stats] = vartestn(vect_for_BF,'TestType','BrownForsythe','Display','off');
%This runs a simple 1 way ANOVA on the column vector
%[p,tbl] = anova1(vect_for_BF, [], 'off');
%fstat = tbl{2,5};
%This will contain the f values for all the tests run
fmap_vis(a,b,c) = fstat1;
fmap_cohort(a,b,c) = fstat2;
fmap_int(a,b,c) = fstat3;
end
end
end
%Saving the degrees of freedom
% df = tbl(5,3);
% Put in the data and save
cd('D:\SAMP\Variability_Project\Code\Creating_MDMsGLMs');
f_Map = xff('3X3X3_3maps.vmp');
f_Map.NrOfMaps = 3;
f_Map.Map = f_Map.Map(1:3);
f_Map.Map(1).Name = 'FMap_Vis';
f_Map.Map(1).VMPData = fmap_vis;
f_Map.Map(2).Name = 'FMap_Cohort';
f_Map.Map(2).VMPData = fmap_cohort;
f_Map.Map(3).Name = 'FMap_Int';
f_Map.Map(3).VMPData = fmap_int;
cd (new_name)
% name2 = ('Brodmann_');
% new_name2 = strcat(name2, areas(i),'.vmp');
f_Map.SaveAs('anova_effect.vmp');
end
%popUp.m
msg = 'All done!';
title = 'all done!';
answer = inputdlg(msg,title);
Sriparna Senhttps://kr.mathworks.com/matlabcentral/profile/authors/16106928-sriparna-sentag:kr.mathworks.com,2005:Question/4857352019-10-16T18:31:28Z2019-10-16T21:24:42ZHow to flip an axis on a plot without affecting the plot?I am trying to rotate the y axis of this plot such that the origin is at the upper left coner of the plot. How would I do so?
This is the code I have to set up my plot.
% Plot averaged vector field
figure(3)
quiver(x(acceptIdx)/48.11,(y(acceptIdx)/48.11),u_avg(acceptIdx),v_avg(acceptIdx),4)
axis([0 42 0 42])
yticks([0 5 10 15 20 25 30 35 40])
set(gca,'XAxisLocation','top','YAxisLocation','left');
xlabel('z (mm)')
ylabel('x (mm)')
title('Dimensional velocity field')
I'd like the y axis to look identical to the x axis.
Thanks. Monique Emburyhttps://kr.mathworks.com/matlabcentral/profile/authors/14608780-monique-emburytag:kr.mathworks.com,2005:Question/4857562019-10-16T21:15:03Z2019-10-16T21:23:44ZTrouble calculating column mean from a matrix - using different indices for each rowHello,
I am trying to calculate a column of means from a 2-D matrix. The length of the mean is equally to the number of rows of the matrix.
However, the index to each row is different. For example, row 1 I want the mean of colums 4 to 8. Row 2 I want the means of columns 3 to 5.
I have tried
mean(myMatrix(:,VariableIndex1:VaribleIndex2))
Where VariableIndex1 and VariableIndex2 are columns for the start and end indices of the columns I need means from
For the example above this would be:
mean(myMatrix(:,[4;3]:[3:5]))
- but this seems to give a non-sensical result.
Any thoughts or advice on how to do this? The column acutally has 100 000 rows so I don't want to loop through it.
Thanks.David McVeahttps://kr.mathworks.com/matlabcentral/profile/authors/7515646-david-mcveatag:kr.mathworks.com,2005:Question/4857582019-10-16T21:21:35Z2019-10-16T21:21:35ZHow do I get data from graph that is plotted in MATLAB Appdesigner?I wrote a program to plot graph in appdesigner.Now I need to get the data from the graph and list it in a table. How do I do that ? This is the graph I got, now I need those values listed in table.
Usha Silwalhttps://kr.mathworks.com/matlabcentral/profile/authors/16206322-usha-silwaltag:kr.mathworks.com,2005:Question/4857442019-10-16T19:25:24Z2019-10-16T21:16:56ZLow Pass filter not workingI audioread() a signal and tried to apply low-pass filtering but it does not seem to have any change at all. The signal is a recording of lung sound and I wish to filter out the noise component.
[y,Fs] = audioread('mysound.wav')
Fs = 44100; % Sampling Frequency (Hz)
Fn = Fs/2; % Nyquist Frequency
Fco = 70; % Passband (Cutoff) Frequency
Fsb = 100; % Stopband Frequency
Rp = 1; % Passband Ripple (dB)
Rs = 10; % Stopband Ripple (dB)
[n,Wn] = buttord(Fco/Fn, Fsb/Fn, Rp, Rs); % Filter Order & Wco
[b,a] = butter(n,Wn); % Lowpass Is Default Design
[sos,g] = tf2sos(b,a);
filt_sig = filtfilt(sos,g,y)
Neither the plot(), FFT() or soundsc() shows anything different. I've tried cheby filters as well. Am I doing anything wrong? Thanks for the help.Yipp Chun Munnhttps://kr.mathworks.com/matlabcentral/profile/authors/14232156-yipp-chun-munntag:kr.mathworks.com,2005:Question/4857552019-10-16T21:14:18Z2019-10-16T21:14:18Zhow can select a specific bits from logical vectors !Hi , i need your help please ,
i have vector contains hex numbers such as :(16-bits)
(0000 0011 1100 0000)
i need select the middel bits from ( b7-b10) then read its as decimal asuch as = 15
i alraedy did that as in the code , but the problem is just work with last row in the vector for my data base ('address.xlsx')! this data base contains 16 rows!
i need find and stor the resuts as vecotr for all my data base numbers not just last elment!
clc;
clear all;
[~,~,dat]= xlsread('address.xlsx');
num=dat(:,1);
for n=1:numel(num)
b=hex2dec ([dat(:,1)]);
b1 = hex2dec('000fff0');
% b = hex2dec ('6e206b'); % for example its work with one elemnt
format hex;
x=bitand(b1,b);
cc=dec2hex(x);
bin=hexToBinaryVector(cc);
ccz=bin((end-flip(7:10)+1));% how can expand this term for all vector!
bp=num2str(ccz);
bp11= bp(find(~isspace(bp)));
v1= bin2dec(bp11);
end
Furat Alobaidyhttps://kr.mathworks.com/matlabcentral/profile/authors/6214076-furat-alobaidytag:kr.mathworks.com,2005:Question/4856972019-10-16T14:54:57Z2019-10-16T21:10:36Zregexprep does not exactly what I wantDear all,
I have the following cell array
Charge = {'OH-1'} {'KOH+0'} {'K+1'} {'I-1'} {'HI+0'} {'H3O+1'} {'H2O+0'}
I want to remove all information before the + and - signs. Therefore I tried the following:
regexprep(Charge,'[^-+].','');
which produces
{'-1'} {'0'} {'1'} {'1'} {'+0'} {'1'} {'0'}
This works well except in case of only one character in front of the minus sign (i.e. in case of I-1). In that case, the - sign is also deleted. The - signs are crucial to be included, the + signs not.
Any suggestions?
Thanks, Timhyblehttps://kr.mathworks.com/matlabcentral/profile/authors/16590099-hybletag:kr.mathworks.com,2005:Question/4857512019-10-16T20:43:56Z2019-10-16T21:08:24Zsolving similtanous equations in loopgiven the two vectors
x = [1,2,3,4,5,6,7]
y = [1,2,3,4,5,6,7]
how can i solve the system of equations (this could be any equation)
-3*w*sin(x)+ 5*q*sin(y)-10 = 0
3*w*cos(x) - 5*q*cos(y) = 0
I need to find the variables w and q in matrix form.
Vincent Gambuzzahttps://kr.mathworks.com/matlabcentral/profile/authors/11813224-vincent-gambuzzatag:kr.mathworks.com,2005:Question/4855502019-10-15T22:47:50Z2019-10-16T20:59:49ZMultivariate Nomral Distribution MatlabI want to generate multivariate normal joint distribution for a 3*3 matrix. Say I have mu = [0.4 0.5] and sigma = [0.25 03; 0.45 0.5]. As I wanted to generate a 3*3 joint distribution, I decided to do the following:
mu = [0.4 0.5];
sigma = [0.25 0.3; 0.3 0.5];
x1 = 1:3;
x2 = 1:3;
[X1,X2] = meshgrid(x1,x2);
X = [X1(:) X2(:)];
y = mvnpdf(X,mu,sigma);
My assumption is that X now has 3*3 matrix index. If the value is 3 1 it means X = 3, Y = 1. For example, if I print the value of X I get:
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3
So, my assumption was the final pdf will be a 9*1 vector and each value will represent the probability of each row. For example, if the second value is 0.05, it will indicate P(X=1,Y=2) = 0.05.
When I gey y, I get the following:
y =
0.3484
0.0471
0.0000
0.0000
0.0027
0.0015
0.0000
0.0000
0.0000
However, as y is a joint distribution, the sum(y) should have been 1. But here it's 0.3997.
Can anyone tell me what am I doing wrong here? And why the sum is not 1?Shahnewaz Karim Sakibhttps://kr.mathworks.com/matlabcentral/profile/authors/15333463-shahnewaz-karim-sakibtag:kr.mathworks.com,2005:Question/4856662019-10-16T12:35:39Z2019-10-16T20:58:07ZFigures not saving as specific file type regardless of specified extensionI am running some code that runs through a directory, takes data from the files, plots the required data form each, and then saves the figure into the same folder before moving onto the next file. The code and processes work fine with the correct data being taken, only when going to the directory where the figures were saved, their extension shows as some number 'file'. e.g. '2 file', '25 file' etc. I can open the fiigure file in paint, but would prefer the file to be saved as what I specified. Here is the code I'm using;
clear all
close all
clc
filedirectory = 'C:\Users\Me\OneDrive\Documents\University\Rogue Waves\Part1\Initial Conditions\Practise\';
filepattern = fullfile(filedirectory, '*.txt');
files = dir(filepattern);
for k = 1:length(files)
filename = files(k).name;
fullfilename = fullfile(filedirectory, filename);
fprintf(1, 'Running simulation for %s\n', fullfilename);
%process data ...
figure, pcolor(tt,xx,abs(u_arr))
xlabel(['Time (s)']);ylabel('Evolution Lab Space (m)');title('Numerics')
shading interp%title(['Nonlinear Time is ' num2str(T_NL,3) ' s, Soliton Period is ' num2str(pi/2*T_D,3) ' s' ])
colormap(jet)
colorbar
str = strcat('Numerics', filename);
savename = strrep(str,'.txt','');
%save the figure in folder
saveas(gcf, fullfile(filedirectory, savename), 'png')
close(gcf)
end
Example of the file extension:
Liam Guesthttps://kr.mathworks.com/matlabcentral/profile/authors/6238144-liam-guesttag:kr.mathworks.com,2005:Question/4857432019-10-16T19:13:45Z2019-10-16T20:55:58ZSubplot problem - plots are on top of each other? I have a script that creates 2 plots. I would like them to be next to each other in a typical subplot form. However, when I run this script, it only plots the second plot and the axes are messed up, such that it looks like it's layering plots on top of each other perhaps. If I take out the subplot syntax and run them as separate figures, they look fine. It's only and issue when I try to use subplot. I cannot figure out what the problem is. I know my code isn't going to win any code beauty pagents, but this is an odd problem I cannot figure out. I'm running 2018a. Thank you all in advance.
%%%Plot Audiograms for SAL
%%%Plot for NH group
%Get NH means from data
IowaNHR_Mean = mean(AudioData.Iowa.NHR);
IowaNHL_Mean = mean(AudioData.Iowa.NHL);
CalNHR_Mean = mean(AudioData.Cal.NHR);
CalNHL_Mean = mean(AudioData.Cal.NHL);
%plot NH group
subplot(1,2,1);
h1 = axes;
plot(IowaNHR_Mean,'r','linewidth',2);
set(h1, 'Ydir', 'reverse');
xlim([0.5 6.5]);
ylim([-20 120]);
set(gca, 'XTick' ,[1 2 3 4 5 6]);
set(gca, 'XTickLabel',{'0.25'; '0.5'; '1'; '2'; '4'; '8'});
grid on
title('Normal Hearing', 'fontsize',25');
ylabel('Threshold (dB HL)', 'fontsize', 20);
xlabel('Frequency (kHz)', 'fontsize', 20);
hold on;
%%Plot Means
plot(IowaNHL_Mean,'b','linewidth',2);
hold on;
plot(CalNHR_Mean, 'r', 'linestyle','--','linewidth',2);
hold on;
plot(CalNHL_Mean, 'b', 'linestyle','--','linewidth',2);
hold on;
%Plot Individual Data
x = 1:6;
y = AudioData.Iowa.NHR;
plot(x,y, 'color', [0,0,0]+0.6);
hold all;
y2 = AudioData.Iowa.NHL;
plot(x,y2, 'color', [0,0,0]+0.6);
hold all;
y3 = AudioData.Cal.NHR;
plot(x,y3,'color',[0,0,0]+0.6, 'linestyle','--');
hold all;
y4 = AudioData.Cal.NHL;
plot(x,y4,'color',[0,0,0]+0.6, 'linestyle','--');
%%Legend
legend('Rural right ear mean','Rural left ear mean','Urban right ear mean','Urban left ear mean','Location','southwest');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%Plot for HL group
%Get HL means fro mdata
IowaHLR_Mean = mean(AudioData.Iowa.HLR);
IowaHLL_Mean = mean(AudioData.Iowa.HLL);
CalHLR_Mean = mean(AudioData.Cal.HLR);
CalHLL_Mean = mean(AudioData.Cal.HLL);
%plot HL group
subplot(1,2,2)
h2 = axes;
plot(IowaHLR_Mean,'r','linewidth',2);
set(h2, 'Ydir', 'reverse');
xlim([0.5 6.5]);
ylim([-20 120]);
set(gca, 'XTick' ,[1 2 3 4 5 6]);
set(gca, 'XTickLabel',{'0.25'; '0.5'; '1'; '2'; '4'; '8'});
grid on
title('Hearing Loss', 'fontsize',25');
ylabel('Threshold (dB HL)', 'fontsize', 20);
xlabel('Frequency (kHz)', 'fontsize', 20);
hold on;
%plot means
plot(IowaHLL_Mean,'b','linewidth',2);
hold on;
plot(CalHLR_Mean, 'r', 'linestyle','--','linewidth',2);
hold on;
plot(CalHLL_Mean, 'b', 'linestyle','--','linewidth',2);
hold on;
%plot individual data
x = 1:6;
y = AudioData.Iowa.HLR;
plot(x,y, 'color', [0,0,0]+0.6);
hold all;
y2 = AudioData.Iowa.HLL;
plot(x,y2, 'color', [0,0,0]+0.6);
hold all;
y3 = AudioData.Cal.HLR;
plot(x,y3,'color',[0,0,0]+0.6, 'linestyle','--');
hold all;
y4 = AudioData.Cal.HLL;
plot(x,y4,'color',[0,0,0]+0.6, 'linestyle','--');
%%Legend
legend('Rural right ear mean','Rural left ear mean','Urban right ear mean','Urban left ear mean','Location','southwest');
Erik Jhttps://kr.mathworks.com/matlabcentral/profile/authors/5606579-erik-jtag:kr.mathworks.com,2005:Question/4697912019-07-02T05:00:59Z2019-10-16T20:52:45ZConnecting database 'MySQL' without using database toolboxHello, I am a student who is using Matlab to perform a project, and I am having some problems with connecting database 'MySQL' without using a database toolbox.
I have found few stuffs like using Activeserver(), ODBC, JDBC Driver, yet It is just too hard for me to understand since I do not have much knowledge in Matlab.
So It would be very appriciated if you could explain in detail.. I need exact steps how to be done connected.
Thank you so much for your time.Jina Sonhttps://kr.mathworks.com/matlabcentral/profile/authors/15727068-jina-sontag:kr.mathworks.com,2005:Question/4857532019-10-16T20:50:17Z2019-10-16T20:50:17Zhello sir why matlab is showing while installinghelo sir my matlab is showing license checkout failed and can u pls suggest me how can i reactivate it againE SOMASEKHARhttps://kr.mathworks.com/matlabcentral/profile/authors/16527075-e-somasekhartag:kr.mathworks.com,2005:Question/4857522019-10-16T20:47:42Z2019-10-16T20:47:42ZWriting a custom annealing functionI'm trying to write my own 'AnnealingFcn' for simulannealbnd, right now I have:
options = optimoptions(@simulannealbnd,'Display','iter','MaxIter',10000,'InitialTemperature',500,'AnnealingFcn',@annealingboltz);
Instead of @annealingboltz, which chooses a direction uniformly at random, I want to write my own function which uses a gaussian with the standard deviation being some function of the temperature. Can anyone point me in the right direction about how to implement this?chhttps://kr.mathworks.com/matlabcentral/profile/authors/6705277-chtag:kr.mathworks.com,2005:Question/4795992019-09-09T17:20:49Z2019-10-16T20:40:25ZUse several pools of workers in a parfor loopHi all,
I am currently trying to figure out if there is a way to use multiple pools of workers in a parfor loop. More precisely, I have 16 cores on my computer (8 physical cores) and until now I was using a classical for loop to perform 20 fminunc optimisations.
While fminunc already performs multiprocessing, I found out that the 16 cores of my cluster where only used to 30%, therefore I was thinking about using some kind of parfor loop over three pools of 5 workers in order to increase the efficiency of the computation and hopefully reduce the time of the computation.
I searched for a while now but didn't really find a way to do that...
Thanks a lot !
Gabrielgmhshttps://kr.mathworks.com/matlabcentral/profile/authors/10396067-gmhstag:kr.mathworks.com,2005:Question/1164492014-02-17T12:51:26Z2019-10-16T20:34:08ZUse quadgk with multiple Inputs with Matlab CoderHi
I want to create a C file out of my Matlab file.
In my Matab file I have to make some integrations, that is way I am using the quadgk function. My problem is now, that the Matlab Coder for generating the C Code doesn't allow function handels.
I want to integrate the function
function val=integrand1(x,c,d)
val=x*c+d;
end
by the follwing term
Integral = quadgk('integrand1',z(1),z(2),-1,z(2))
So the intergal goes from z(1) to z(2) and for the parameters c and d I want to use the values -1 and z(2).
If I do so the Matlab Coder gives the errow
??? First input argument must be a function handle.
But how can I use quadgk instead?
Thank you very much for any help.
Best regards AntoniaAntonia Lichteneggerhttps://kr.mathworks.com/matlabcentral/profile/authors/2124854-antonia-lichteneggertag:kr.mathworks.com,2005:Question/4857492019-10-16T20:24:39Z2019-10-16T20:24:39Zhow to add simulink if I already have MatLab application and license?I already download and activated simulink 2019b. But there's no simulink's fiture Marini Nur Shadrinahttps://kr.mathworks.com/matlabcentral/profile/authors/16151407-marini-nur-shadrinatag:kr.mathworks.com,2005:Question/3047732016-09-27T19:18:12Z2019-10-16T20:20:51ZHow can i compress the text file using huffman encoding?Hi
I am using a text file to hide inside an image file in lsb plane.
But i want to compress the text file using huffman encoding and hide inside the lsb plane of image file.
After retrieve the text file, the text file should be decompressed using huffman encoding.
Can you help in this matter.
Sanjeeb Beherahttps://kr.mathworks.com/matlabcentral/profile/authors/8566904-sanjeeb-beheratag:kr.mathworks.com,2005:Question/4857482019-10-16T20:20:49Z2019-10-16T20:20:49ZHow to interpolate over long section of bad data?Hello all,
I'm very new to MATLAB (and coding in general) so forgive me if I don't explain the problem well. Basically I have a large dataset from an experiment during which the analyzer equipment malfunctioned. I want to interpolate over a long section of data for 2 variables (VO2 and VCO2). Here's a sample of the data (VO2; starting with 3 good data points, 3 empty data points when the equipment malfunctioned, and then 3 data points following the empty cells that I don't believe are accurate):
I've tried this code so far:
x = 1:4076;
yVO2 = VO2(1:4076);
yVCO2 = VCO2(1:4076);
xq = x;
splineVO2 = spline(x,yVO2);
splineVCO2 = spline(x,yVCO2);
interpVO2 = ppval(splineVO2,xq);
interpVCO2 = ppval(splineVCO2,xq);
And the returned interpolated values match the original values. I've tried this same code with only cells I want to interpolate over (2407:2822) and I get the same result. I've also tried this same code but with xq as an input argument in the spline function ( splineVO2 = spline(x,yVO2,xq); ) and have gotten the same result.
I'm guessing I'm doing something wrong with defining xq but I'm not sure.
Thanks in advance!Katie Colferhttps://kr.mathworks.com/matlabcentral/profile/authors/16592895-katie-colfertag:kr.mathworks.com,2005:Question/4855162019-10-15T18:25:05Z2019-10-16T20:19:42ZPut block behind colorbarI have several contour plots on a cylinder that I made in MatLab. In some of them the black text from the colorbar is obstructed by dark colors in the plot. In others, the color of the text is fine so I would rather not change the color of the text. Is there an easy way in MatLab to put a rectangular patch (either white or gray) neatly around the colorbar and the surrounding text but behind it so that only a small amount of the contour is hidden?
I've given a link to 4 .fig files on google drive (they're too big to attach), and a .png of one of them where I put a white block around the colorbar (I would like it to be filled and behind the colorbar but in front of the contour) to show what I am hoping to get.
https://drive.google.com/open?id=14cH1OCuL7-poWk2xckzuETazETpyMm28
Nathaniel H Wernerhttps://kr.mathworks.com/matlabcentral/profile/authors/9280119-nathaniel-h-wernertag:kr.mathworks.com,2005:Question/4778182019-08-27T23:12:56Z2019-10-16T20:18:24ZI can acess bit by bit of pixel in an image with Matlab?I'm doing a work about steganography. And I want to acess bit by bit of a pixel in an image. I can do this with matlab?Weslley Eduardohttps://kr.mathworks.com/matlabcentral/profile/authors/15675005-weslley-eduardotag:kr.mathworks.com,2005:Question/4857472019-10-16T20:17:54Z2019-10-16T20:17:54ZGenerate a random sequence with assigned probabiitySuppose we have 4 symbols [1 2 3 4] with each having probability []0.5 0.1250 0.1250 0.250]
How can i generate a sequence randomly accordiing to the assigned probabilities?
Shailee Yagnikhttps://kr.mathworks.com/matlabcentral/profile/authors/11759058-shailee-yagniktag:kr.mathworks.com,2005:Question/4857212019-10-16T16:59:43Z2019-10-16T20:13:39ZHow do i plot a 3D structure as in the attached picture?<</matlabcentral/answers/uploaded_files/242993/Capture.PNG>>
I want to plot a mesh like in the attached picture.
1. Lengths of each sides are specified ( L and W)
2. Number of horizontal and vertical lines are fixed ( m and n)
3. Distance between parallel lines are same (d1 and d2)
4. Perpendicular legs all have same length(H)
5. Perepndicular legs are placed at various intersections depending upon some condition.Ni2https://kr.mathworks.com/matlabcentral/profile/authors/16591620-ni2tag:kr.mathworks.com,2005:Question/1726132015-01-28T04:38:34Z2019-10-16T20:05:52ZTrouble getting the correct graphI am having trouble obtaining the correct graph for the given problem:
Plot the function f(x)= (0.5x^3-x^2)/(x^2-x-20) for -15=<x=<15. Notice that the function has two vertical asymptotes. Plot the function by the domain of x into three parts: one from -15 to near the left asymptote, one between the two asymptotes, and one from near the right asymptote to 15. Set the range of the y-axis from -20 to 20.
I thought my script would be correct, but the graph is totally wrong. Any help is greatly appreciated. Thank you in advance! Here is my script:
% Plot f(x)= (0.5x^3-x^2)/(x^2-x-20)
clear all
% Create an array of x-values for -15<x<-4
x1= -15:0.05:-4.1;
% Create an array of x-values for -4<x<5
x2= -3.9:0.05:4.9;
% Create an array of x-values for 5<x<15
x3= 5.1:0.05:15;
% Create y-values for -15<x<-4
y1=(0.5*x1.^3-x1.^2)/(x1.^2-x1-20);
% Create y-values for -4<x<5
y2=(0.5*x2.^3-x2.^2)/(x2.^2-x2-20);
% Create y-values for 5<x<15
y3=(0.5*x3.^3-x3.^2)/(x3.^2-x3-20)
% Multiple plots on one set of axes
plot(x1,y1,x2,y2,x3,y3)
% Plotting limits for the x-axis and y-axis
axis([-15 15 -20 20])
Clairehttps://kr.mathworks.com/matlabcentral/profile/authors/5121260-clairetag:kr.mathworks.com,2005:Question/4853132019-10-14T21:46:41Z2019-10-16T20:04:36ZHow can I save data from features files into matrix?i want to save data from 500 images features files every file contain 6 types of features types such as jcd,tamura,..... .,
the problem is that the data for these 6 features are seperated by comma,i want to make six matrices for these 500 image for type of features ,i atteched this file to help
can any one helpbahaa rabihttps://kr.mathworks.com/matlabcentral/profile/authors/16569365-bahaa-rabitag:kr.mathworks.com,2005:Question/4856872019-10-16T13:59:29Z2019-10-16T20:02:50Zanyway to give separate color to 'stack' bar plot Hi:
I read an post from link below:
https://www.mathworks.com/matlabcentral/answers/175955-how-to-assign-a-label-to-each-bar-in-stacked-bar-graph
which provide a way to add annotation to the individual of each data. I would like to know if there is anyway to control the color of each individual bar?
Thanks!
YuYu Lihttps://kr.mathworks.com/matlabcentral/profile/authors/13996926-yu-litag:kr.mathworks.com,2005:Question/4855692019-10-16T01:38:27Z2019-10-16T20:01:21ZBandwidth analysis of a system with multidimensional inputI am playing around with the built-in bandwidth function.
I can intuitively understand what is going on under the hood for a transfer function with scalar input and scalar output. However, how is the band width computed when the input is a vector of length > 1?
For instance, as in this example from the documentation:
A = [-2 -1; 1 0];
B = [1; 0];
C = [1 2];
D = 1;
sys = ss(A,B,C,D);
bandwidth(sys)HaMohttps://kr.mathworks.com/matlabcentral/profile/authors/3016326-hamotag:kr.mathworks.com,2005:Question/4857302019-10-16T17:51:08Z2019-10-16T19:52:11ZDefine an if statement based on on finding duplicate values between arrays and then rewrite code to be able to handle multiples values/variablesHello, I have 2 arrays of different sizes which I am trying to compare for duplicates using an if statement. The condition to activate this section of the code should be if there are any duplicate values in between the two arrays then do these commands. The commands are written for just the specific case, but I want to make it more general and adaptable for different scenarios. Right now, it only works with one value being stored in inot2keep but there could be mutiple numbers which it wouldnt be able to handle under the current storage method. Any ideas or tips for improvement will be greatly appreciated thank you. Also I know that I switch variable names a lot and its confusing.
% test for find repeat combined vein nodes/vectors
if newVN_prime10 == vein_node_array % if any values in the 2 arrays are equal this code should activate the loop
VN_VN_threshold = ((1/2)*radii_vein); % if distance between VNs is greater than this value then point should be retained
SizeNewVN_prime10 = size(newVN_prime10, 1);
newVN_prime10x = newVN_prime10(:,1);
newVN_prime10y = newVN_prime10(:,2);
reconfig_dist10 = nan(numel(VNA_x)); % preallocation step
for j = 1:SizeofVNA
for i = 1:SizeNewVN_prime10
reconfig_dist10(j,i) = sqrt((newVN_prime10x(i)-VNA_x(j)).^2 + (newVN_prime10y(i)-VNA_y(j)).^2);
end
end
% find the points that are greater than VN_VN_threshold
i2keepVN_VN = find(min(reconfig_dist10)> VN_VN_threshold); % keeps the VN points that pass the test
inot2keepVN_VN = find(min(reconfig_dist10)< VN_VN_threshold); % keeps the VN points that fail the test
% store points greater than VN_VN_threshold
x_newVN_retained = newVN_prime10x(i2keepVN_VN);
y_newVN_retained = newVN_prime10y(i2keepVN_VN);
% store points less than VN_VN_threshold
x_notkept = newVN_prime10x;
y_notkept = newVN_prime10y;
x_notkept(i2keepVN_VN) = [];
y_notkept(i2keepVN_VN) = [];
newVN_retained = [x_newVN_retained, y_newVN_retained]; % store new vein nodes the pass test
VN_VectorGroupNum = inot2keepVN_VN; % VN group # needs to be kept for linking back to proper VNA point
VN_reconfig = VN_HSvectors10{VN_VectorGroupNum}; % grabs the vector group that makes up repeated combined vector
VN_HScomb10Beta = 8*(VN_reconfig./vecnorm(VN_reconfig,2,2)); % turns vector group into scaled unit vectors
SizeVN_HScomb10Beta = size(VN_HScomb10Beta,1);
VNconfig_beta = VN_HScomb10Beta(:,:) + vein_node_array(GroupList10(VN_VectorGroupNum),:); % adds reconfigured vectors to appropriate vein node chain
end % end of if statement
Vance Blakehttps://kr.mathworks.com/matlabcentral/profile/authors/15947118-vance-blaketag:kr.mathworks.com,2005:Question/4855462019-10-15T21:53:33Z2019-10-16T19:52:04ZAlpha Blending 2 Matrix Images i have a 512 x512 matrix image called original, a 20x24 matrix image of a bright oval with lower (darker but not zero) values around the oval in the 20x24 matrix called insert, and the same 20x24 matrix image of the bright oval but with zeros around the oval and ones in the oval (binary image) called mask
and a mask of the oval in a 512 512 matrix
i want to place the matrix insert in a specific location in the matrix original (i know how to do this)
then i would want a spatially dependent alpha blender: so the mask can be used to know where the oval is in the 512x512 matrix and the alpha in those pixels would be 0(the pixel value would be 100% of the value in insert and nothing of the background original matrix) Then, pixel by pixel, as you get farther away from the oval, it blends the value of the pixel in the matrix insert and the pixel under the insert matrix(which would be in the original matrix) until it reaches the edge of the insert matrix (alpha would be 1 here meaning it is taking the value of 100% background original matrix and 0% if the insert matrix)
Can you please show me how to write code for this. I do not have examples or images i can provide
Thanks
Mike Rovanhttps://kr.mathworks.com/matlabcentral/profile/authors/16354169-mike-rovantag:kr.mathworks.com,2005:Question/4855542019-10-15T23:45:54Z2019-10-16T19:52:00ZI can not run the Delfino TMS320F28379D Launchpad in external mode in order to tune parameters.My simulink model is generating a PWM signal with a duty cycle indicated by the constant block.
It works fine when I deploy to hardware, but is not working when I try it in external mode. I want to modify the duty cycle while it is running.
This is what I have set in configuration parameters;
I am attaching the simulink model as a zip file too.
Any help would be appreciated.Jafet Martínezhttps://kr.mathworks.com/matlabcentral/profile/authors/4623845-jafet-martineztag:kr.mathworks.com,2005:Question/4857422019-10-16T18:54:59Z2019-10-16T19:48:46ZHow to assign to an already 3d surface a colormap based on a set of values ?Hi guys, let imagine that I've already plotted a 3d surface, let be for reason of simplification a semicylinder (so displayed as a function using surf). Now I want to modify every single point/(piece of surface) color of this surface based on a set of value, for example I have computed the temperature point to point on that surface, now I just want to show that variation on the surface, in the sense of colormap. I know that it is possibe doing this with a 2D plot, simply by plotting the matrix of Temperature on a surf(T) and see the plot from the top, but I would like to see that on the geometry.Marco Artianohttps://kr.mathworks.com/matlabcentral/profile/authors/13671913-marco-artianotag:kr.mathworks.com,2005:Question/4856882019-10-16T14:16:59Z2019-10-16T19:41:28ZHow to turn scatterplot labels on and off using uicontrolHello dear matlabbers,
I tried to create a scatterplot with labels for each point (link here: 1).
Now I would like to give the user of the code the possibility to turn the labels on and off. I appreciate any help and comments! Thanks a lot in advance!
So far my code looks like this:
x = rand(1,100); y = rand(1,100); pointsize = 30;
idx = repmat([1 : 10], 1, 10) % I used class memberships here
figure(1)
MDSnorm = scatter(x, y, pointsize, idx, 'filled');
dx = 0.015; dy = 0.015; % displacement so the text does not overlay the data points
T = text(x + dx, y +dy, labels);
colormap( jet ); % in my code I use a specific colormap
Button = uicontrol('Parent',figure(2),'Style','toggle','String',...
'labels','Units','normalized','Position',[0.8025 0.82 0.1 0.1],'Visible','on',...
'callback',{@pb_call, MDSnorm, ???});
At the end of my script I then tried to define the pb_call function. I tried out several different versions, they all failed. Unfortunately, I am not skilled enough to translate any tutorials to my specific problem.
I have a rough idea what I need to do...
function [] = pb_call( ??? )
if get(Button, 'Value')
T --> invisible % ???
else
T --> visible % ???
end
end
Frederik Bergmannhttps://kr.mathworks.com/matlabcentral/profile/authors/8545127-frederik-bergmanntag:kr.mathworks.com,2005:Question/4847352019-10-11T08:15:55Z2019-10-16T19:39:46ZConvert transfer function to state-space modelsI'm trying to convert a transfer function to state space model.
The transfer function that I'm using is quite simple. Is the model for a heatsink temperature.
For this transfer function I have the next values for A,B,C and D.
I've tried to compare the output from the lsim() function and the equations from above but the output differs
Here's the code that I've used
P = rand(1,10)*1000;
t = 0:1:length(P)-1;
A = -400;
B = 0.5;
C = 0.6658;
D = 0;
%%%%%%%%%%%%%%%%%%%%%%%%%
%%% State space %%%
%%%%%%%%%%%%%%%%%%%%%%%%%
state_space_sys = ss(A,B,C,D);
state_space = lsim(state_space_sys,P,t);
figure
plot(t,state_space)
grid on,grid minor, title('State space')
%%%%%%%%%%%%%%%%%%%%%%%%%
%%% My function %%%
%%%%%%%%%%%%%%%%%%%%%%%%%
x(1:length(P)) = 0;
y(1:length(P)) = 0;
u = P;
for k = 1:length(u)
x(k+1) = A*x(k) + B*u(k);
y(k) = C*x(k) + D*u(k);
end
figure
plot(t,y)
grid on,grid minor, title('My function')
Is there any mistakes on the approach?
It should be quite simple, but I can't manage to find the solution.Diego Garciahttps://kr.mathworks.com/matlabcentral/profile/authors/4612757-diego-garciatag:kr.mathworks.com,2005:Question/4857462019-10-16T19:38:01Z2019-10-16T19:38:01ZSimulink error with integrator I am trying to simulate a mechanical dynamical system and I am getting hte following error :
Derivative of state '1' in block 'HW3que2d_least_sq/Integrator3' at time 0.0 is not finite. The simulation will be stopped. There may be a singularity in the solution. If not, try reducing the step size (either by reducing the fixed step size or by tightening the error tolerances)
What should I do further to remove the error.
I have also attached my simulink model.
Any help would be really appreciated.Arpita Petkarhttps://kr.mathworks.com/matlabcentral/profile/authors/13651030-arpita-petkartag:kr.mathworks.com,2005:Question/4857182019-10-16T16:49:31Z2019-10-16T19:37:27ZNonlinear Equation solution of one variable ?I'm trying to solve this modified effective permittivity non linear equation using newton raphson method, the solution does not return a pair of complex solution, could anyone help me with coding!
p=[0.23]
er1=(10000); % first relative permttivity
er2=(2.5); % second relative permttivity
Hc=(10^6);
H=[0,2.5*10^4,5.0*10^4,7.5*10^4,1*10^5,1.3*10^5,1.5.*10^5];
Pc=(0.33).*exp(-abs(H)/Hc);
c1=(1-3*Pc).*(((p)./(Pc)).^Pc).*(((1-p)./(1-Pc)).^(1-Pc)); %concnetration
% wanted solution for varaible x
f=@(x) ((p.*(x-er1)./(er1-2.*x))./(1+c1.*(x-er1)./(er1-2.*x))+((1-p).*(x-er2)./(er2-2.*x))./(1+c1.*(x-er2)./(er2-2.*x))); %Equation 4
df=@(x) ((3.*er1.*p)./(er1+2.*x+c1.*(x-er1)).^2)+(((x-er2).*(1-p))./(er1+2.*x+c1.*(x-er1))); %derivative of the above function
a=1; b=20;
x=a;
for i=1:1:100
x1=x-(f(x)/df(x));
x=x1;
end
sol=x;
fprintf('Approximate Root is %.15f',sol)
a=1;b=20;
x=a;
er(5)=0;
for i=1:1:5
x1=x-(f(x)/df(x));
x=x1;
er(i)=x1-sol;
end
plot(er)
xlabel('Number of iterations')
ylabel('Error')
title('Error Vs. Number of iterations')
i had attached the wanted equation solution in the picture attachments.Ammar Ahmedhttps://kr.mathworks.com/matlabcentral/profile/authors/14992209-ammar-ahmedtag:kr.mathworks.com,2005:Question/2991692016-08-10T18:09:56Z2019-10-16T19:37:04ZAutomatically generate program logic flow chart from mfile?I just discovered <http://code2flow.com/# code2flow> which is great for mapping out the logical flow of code, for example when debugging. However it requires you enter pseudo code, or you can run it on existing javascript or Python code. I would love if there was a similar tool that would let you make a visual representation of the logic flow of an mfile. Does this exist?K Ehttps://kr.mathworks.com/matlabcentral/profile/authors/1596298-k-etag:kr.mathworks.com,2005:Question/4857452019-10-16T19:37:02Z2019-10-16T19:37:02ZThickness variation estimate from 3D point cloudIs there any way to estimate thickness variation in my ~ 2"X 4" steel plate approximately 4 mm thick?. I have the 3D point cloud scanned and imported into MATLAB. Thanks.DAMILOLA BALOGUNhttps://kr.mathworks.com/matlabcentral/profile/authors/16441144-damilola-baloguntag:kr.mathworks.com,2005:Question/4419522019-01-28T22:37:46Z2019-10-16T19:25:21ZGetting the Incorrect PlotI have a function (func) given to me with desired x-values (x). The assignment is to plot func while also plotting the x-intercepts. It appears to me that I am getting the correct values when I check the x/y data points, but the graph does not line up.
x = -10:.1:8;
func = (x-6).*((x.^2)-1).*(x+8);
plot(func);
title("Graph of Function");
xlabel("Vector Values");
ylabel("Function Values");
hold on;
%Plots the x-intercepts
[~,cols] = size(func);
for i=1:cols
if func(i) == 0
plot(x(i),0,'*r')
end
end
The x-intercepts are correct and the data points are correct; however, my plot does not line up. Not sure what is wrong. Any help would be great!Jonathan Fletcherhttps://kr.mathworks.com/matlabcentral/profile/authors/11947843-jonathan-fletchertag:kr.mathworks.com,2005:Question/4857362019-10-16T18:34:05Z2019-10-16T19:10:22ZRead 2 frames simultaneously from same videoI want to do some video processing, and i need two frames contiously. the two frames need be right after each other, so i am able to compare them, either being subtracting or else.
clc; clear all;
Video = VideoReader('VID_1.mp4','CurrentTime',11);
opticFlow = opticalFlowLK('NoiseThreshold',0.009);
h = figure;
movegui(h);
hViewPanel = uipanel(h,'Position',[0 0 1 1],'Title','Plot of Optical Flow Vectors');
hPlot = axes(hViewPanel);
while hasFrame(Video)
frameRGB = readFrame(Video);
frameGray = rgb2gray(frameRGB);
frameRGB2 = readFrame(Video,CurrentTime+1); % I need help here...
flow = estimateFlow(opticFlow,frameGray);
imshow(frameRGB2)
hold on
plot(points.selectStrongest(50));
plot(flow,'DecimationFactor',[5 5],'ScaleFactor',100,'Parent',hPlot);
hold off
pause(10^-3)
endLukas Wyonhttps://kr.mathworks.com/matlabcentral/profile/authors/8773854-lukas-wyontag:kr.mathworks.com,2005:Question/4857412019-10-16T18:51:42Z2019-10-16T19:06:53ZHow can I plot this functionI want to plot this function in the interval
Thank youEssid Atefhttps://kr.mathworks.com/matlabcentral/profile/authors/12127192-essid-ateftag:kr.mathworks.com,2005:Question/4856412019-10-16T10:11:52Z2019-10-16T19:05:24Zhow to find inverse hi. I have a question. how can I solve this: if f(x)=x^2/1+sqrt x how can i find finvese(2)?Sabri Kennohttps://kr.mathworks.com/matlabcentral/profile/authors/16136393-sabri-kennotag:kr.mathworks.com,2005:Question/4857322019-10-16T17:54:04Z2019-10-16T18:57:34Zwhy my code doesnt work?clc;
clear;
clear all;
%read image
imdata=imread('image.jpg');
%show image
imshow(imdata);LAXMI PRIYANKAhttps://kr.mathworks.com/matlabcentral/profile/authors/16587274-laxmi-priyankatag:kr.mathworks.com,2005:Question/4845652019-10-10T10:01:02Z2019-10-16T18:56:21ZR-Squared in Curve-fitting ToolHello,
to evaluate my modell i am using the Curve fitting Tool. I loaded my data. And i want to calculate the R-Squared .So i set a Polynom first degree (y = x) as a reference.
The problem is, for every Robust mode ( Off , bisquare , LAR) i get a different R-squared value even though data and the reference ( line y= x) didn#t change.
Do you have an explanation ?
Thanks.
Mohamed Amine Ben El Mechrihttps://kr.mathworks.com/matlabcentral/profile/authors/8951368-mohamed-amine-ben-el-mechritag:kr.mathworks.com,2005:Question/4856862019-10-16T13:58:13Z2019-10-16T18:55:58Zhow to plot individual particle velocites in a closed space i had some spherical particles which will be moving with time i had the velocity data but to plot contour i need to assign to grid how to do thisbharathi Dasarihttps://kr.mathworks.com/matlabcentral/profile/authors/15693635-bharathi-dasaritag:kr.mathworks.com,2005:Question/4857232019-10-16T17:18:23Z2019-10-16T18:54:45ZSimulink gradually changing a value from its original to desiredOn Simulink how do I gradually change an output (e.g. motor speed) from its original value to the desired value to avoid it 'jumping' from one value (speed) to another?
Thanks in advance!Edward Grovehttps://kr.mathworks.com/matlabcentral/profile/authors/9393834-edward-grove