https://au.mathworks.com/matlabcentral/answers/questionsMATLAB Answers — New Questions2021-01-16T06:44:32Ztag:au.mathworks.com,2005:Question/7179002021-01-15T13:11:10Z2021-01-16T06:44:32ZUsing addpath on Compiled Code Hello. I have run into a problem using a compiled EXE of my code on a target computer (running the MCR)
On my computer where I create the code (and have Matlab installed) - I succesfully connect to a linear stage
%% Load PI MATLAB Driver GCS2
% (if not already loaded)
addpath ( 'C:\Users\Public\PI\PI_MATLAB_Driver_GCS2' );
if ( ~exist ( 'Controller', 'var' ) || ~isa ( Controller, 'PI_GCS_Controller' ) )
Controller = PI_GCS_Controller ()
end;
%% Start connection
%(if not already connected)
boolPIdeviceConnected = false; if ( exist ( 'PIdevice', 'var' ) ), if ( PIdevice.IsConnected ), boolPIdeviceConnected = true; end; end;
if ( ~(boolPIdeviceConnected ) )
% USB
controllerSerialNumber ='020550023'; %'Enter valid serial number here, e.g. "123456789"'; % Use "devicesUsb = Controller.EnumerateUSB('')" to get all PI controller connected to you PC.
% Or look at the label of the case of your controller
PIdevice = Controller.ConnectUSB ( controllerSerialNumber );
% Query controller identification string
connectedControllerName = PIdevice.qIDN()
Whilst this works fine it doesn't work on my compiled version on the target computer and its throwing an addpath error. Doing some searching I see that I shouldn't use addpath in compiled versions of my code.
So do I need to include all the files in the following folder :
C:\Users\Public\PI\PI_MATLAB_Driver_GCS2\@PI_GCS_Controller
If I check ctfroot on the target computer I get.
C:\Users\Scan\AppData\Local\Temp\Scan\mcrCache9.9\HPBR_60
So do I just place my the folder I need access to in the ctfroot directory?
If not whats the solution?
Thanks
JasonJasonhttps://au.mathworks.com/matlabcentral/profile/authors/1217570tag:au.mathworks.com,2005:Question/7149432021-01-12T15:41:19Z2021-01-16T06:42:33ZApp Designer Uneditable CodeHello! What I am trying to do is have a 'automated picking list.' In other words, I will have a checklist of item. (I.e. Apple, pear, banana). Each of the items have a specific barcode, 321, 654, and 987 respectively. So, when an item is scanned, I would like it to be automatically 'checked' off the list. Below I put a matlab script with the general idea. I want to implement this logic with the App Designer Toolbox, however I am not able to edit the. Anything with a white background is editable, and a grey background is uneditable. I want to implement the for and if else loops in the .m code to line 49, the value of the checkbox, to change it's toggle instead of print a statement but I cant edit it! any suggestions?
barcode = [321 654 987];
prompt = 'Enter a string of digits to represent a barcode: ';
x = input(prompt);
c = 0;
%For loop will check if scanned item is within list, if so will mark c = 1
for i = 1:length(barcode)
if barcode(i) == x
c = 1;
end
end
%If loop will check item if c = 1
if c == 1
disp('Item Checked!')
else
disp('ERROR: Item Not Required')
endSebastian Cacereshttps://au.mathworks.com/matlabcentral/profile/authors/14385927tag:au.mathworks.com,2005:Question/7121582021-01-08T18:40:04Z2021-01-16T06:29:54ZHow to compare two frequency time graphs?I am an undergraduate and new to matlab. i am doing my project in audio signal processing. can someone help me in drawing two frequency - time graph and compare them to mark the dissimilarities......
Thank you in advance...
Thenuja.JThenuja Jeyakanthanhttps://au.mathworks.com/matlabcentral/profile/authors/20708030tag:au.mathworks.com,2005:Question/7183652021-01-16T06:28:37Z2021-01-16T06:29:35ZHow to convolve a wavelet with a signal to make a wedge model?I would appreciate if anyone can help me as I am new in MATLANB :(.
I have a signal and I want to convolve it with a wavelet and make a wedge mode. It is a seismic wedge model.Appreciated in advance!
My wavelet code is:
%.............................................
fr=30;% frequency
dt=.002;
T=0.1;
tt=-T:dt:T;
tsh=0.008;%time shifting
tr=round(length(tt)/2);
t=tt(tr:end);
zpr=(1-tt.^2*fr^2*pi^2).*exp(-tt.^2*pi^2*fr^2);%zero-phase ricker
figure(10)
plot(zpr)
%................................................
My signal is:
%...............................................
data=xlsread('1');
amp=data(:,2);%us/f
time=data(:,1);%ms
tim=time(1:1:end);
am=amp(1:1:end);
len=length(tim);
for i=1:len
if am(i)==-999.25
am(i)=am(i-1);
end
end
data1=zeros(len,2);
tti=round(tim);
for j=2:len
r(j)=(am(j)-am(j-1))/(am(j)+am(j-1));% reflection coefficients
end
plot(r)Maria Amrhttps://au.mathworks.com/matlabcentral/profile/authors/16529053tag:au.mathworks.com,2005:Question/7183702021-01-16T06:29:09Z2021-01-16T06:29:09Zhow to implement Bessel's function in MATLAB
i want to find the solution of this bessels function mentioned
please help me to model the same in matlab or simulinkNIHAD MOHAMED ALIhttps://au.mathworks.com/matlabcentral/profile/authors/18893696tag:au.mathworks.com,2005:Question/7176602021-01-15T07:28:00Z2021-01-16T06:25:27ZJoin disconnected terminal points of components in a binary imageHI everybody!
I am working on flame edge detection. What I need is two single loops to depict two different flame edges. I have attached the binary image of my flame edge below:
(Please open the image in a different window to view it properly)
Let's talk about the left half of the image to keep things simple. If you look at the left half of the image, you will see that there isn't a single loop, as the edge touches itself at different points. A magnified image is attached below:
My primary objective is to remove the appropriate cells so that I can have one closed loop. I might have to remove some parts of the origibal edge, but I think that's okay. To accomplish this, I complemented the original binary image, and used the following code to specify the objects that have 4-connectivity (Please correct me here if I am wrong):
complement = imcomplement(fb2); % fb2 is the origibal binary image matrix
BW2 = bwareafilt(complement,3,4);
BW3 = imcomplement(BW2);
imshow(BW3);
fb2 is the binary image matrix file, attached with the question.
One of the problematic areas (from the left half of the above image) is shown below:
Thereafter I used the answer given on this page to remove the cells having 2 neighbours:
numberNeighboringPixels = 2; % Can also be 1 or 3
% Using Lookup Table
lut = makelut(@(x)sum(x(:))==(numberNeighboringPixels+1),3);
BW3_LUT = bwlookup(BW3,lut) & BW3;
%%Plot and show the results are the same figure
% subplot(1,2,1);
% imshow(BW3); title('Original Image');
% subplot(1,2,2);
imshow(BW3_LUT);
BW3_LUT gives me the following image:
Unfortunately, the above code causes discontinuities in the edge. Magnifying the discontinuity inn the left loop of the above figure:
This means that instead of 2 disconnected components (corrsponding to two closed loops) that I want in my image, I have n>2 disconnected components; in this case: 8. I have color code all the components for better visualization:
A magnified version of the color coded discontinuity:
I then thought that if I am able to find the terminal points of the components, I might be able to connect them. I use the following code to find the endpoints (taken from this answer):
BW3_LUT = bwareaopen(BW3_LUT,2); % to remove isolated cells
[L, Num] = bwlabel(BW3_LUT);
for K = 1 : Num
[epr{K}, epc{K}] = find( bwmorph(L == K, 'endpoints') );
end
Although I now have the end points, the components are not labeled according to the sequence I want to join them. Also, I don't know how to join the end points. I can use the Bresenham's Line Algorithm, but I can use that only after I can sequence the components properly (through code), which means "n-th component connects to n+1-th component. I can separate the two halves of the original binary image in order to do this.
In the end, my main objective is to have one single loop for one flame edge. I might be using a wrong approach, but this is what I can think of right now. I am losing some of the "wrinkled" features of the edges, but that is okay as long as I don't lose all of them. Please help me with this issue. Let me know if there are any more clarifications I need to make.
Ankit Sahayhttps://au.mathworks.com/matlabcentral/profile/authors/14907708tag:au.mathworks.com,2005:Question/7175852021-01-15T04:45:54Z2021-01-16T06:10:47ZRemove black pixels from RGB image.I know that variations of this question get asked a lot on here, but I haven't found a solution that works for my problem very well.
How do I remove the black border from the image above programmatically, but not by using imcrop!? I would prefer to find & remove all of the black pixels in the image, by effectively deleting that data--leaving me with a (yes) cropped image that contains only the color region of this image. My attempt is as follows:
% define scale bar:
firstFrame = read(vidObj,1);
imshow(firstFrame,'InitialMagnification',300);
title('Define the scale bar region:','FontSize',16);
scaleBar = drawrectangle('Color',[1 1 0]);
roi_Bar = scaleBar.Position;
% cropped and screwed:
I = imcrop(firstFrame, roi_Bar);
figure;
imshow(I);
% remove black border:
mask = (I(:, :, 1) == 0) & (I(:, :, 2) == 0) & (I(:, :, 3) == 0);
I(mask) = [];
figure;
imshow(I); % this returns a horrific result
Many thanks in advance! Luke G.https://au.mathworks.com/matlabcentral/profile/authors/11209081tag:au.mathworks.com,2005:Question/7183552021-01-16T05:42:40Z2021-01-16T05:44:55ZMATLAB vs. LabVIEW for Hardware Communication?I'm building a pressure-volume testing setup (schematic below). I've already run into a couple issues--e.g., communicating with Arduino (asked about on MATLAB Central) & now I'm getting extremely noisy data from the pressure transducer. Looking for advice, people have told me to switch to LabVIEW, saying that "MATLAB is best for numerically intense tasks (e.g., large data sets), but LabVIEW is best for control and data acquisition." Thoughts?
FYI: I would prefer to keep coding in MATLAB, but if it's not good at data acquisition I need to find another solution for my experiments.Luke G.https://au.mathworks.com/matlabcentral/profile/authors/11209081tag:au.mathworks.com,2005:Question/7175802021-01-15T04:23:27Z2021-01-16T05:42:35Z complementary error function (surf plot)I'm new to MATLAB and i'm trying to plot the following function with surf:
.
Parameter values:
My code so far:
x = linspace(0,10^(-6),20);
t = linspace(0,5,5);
u0 = 10^(-6);
k = 10^(-9);
dn = 2.*k.*sqrt(t);
e2 = erf( x.*(dn).^(-1) );
u = u0.*(1 - e2);
surf(x,t,u)
title('Complementary Error function from 0 to 10^(-6)')
xlabel('Distance x')
ylabel('Time t')
I'm trying to get the x between 0 to in increments of and t in increments of .
How do you fix this?Stephanie Andersonhttps://au.mathworks.com/matlabcentral/profile/authors/20889786tag:au.mathworks.com,2005:Question/6892292020-12-10T04:36:20Z2021-01-16T05:39:35ZLSTM padding and maskingI am solving a sequence-to-sequence classification problem based on LSTM using Matlab 2020b. The sequences have varaible length so padding within each minibatch is needed. However, I am not sure if Matlab automatically do the masking when calculating the crossentroy loss as well as the training/validation accuracy. From the training plot, the reported accuracy (around 70%) is much lower than those manually calculated by using checkpoints (where I get around 90% accuracy). I suspect although Matlab 2020b supports sequence padding and validation data in LSTM, it still did not offer the option of masking to reduce the influence caused by padding. Any insights?Ao Duhttps://au.mathworks.com/matlabcentral/profile/authors/8871960tag:au.mathworks.com,2005:Question/7183502021-01-16T05:36:03Z2021-01-16T05:36:03ZCreating a fourth column of my codeI have the following codes:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
format longg
f= @(x) sin(x);
x0 = 2;
ref = cos(2);
hs = 10.^(-(1:16));
errors = [];
for h = hs
derivative = (f(x0+h) - f(x0-h))/(2*h);
error = abs(ref - derivative);
rate = [error(1); error(2:end)./error(1:end-1)];
errors = [errors error] ;
disp([h derivative error rate])
end
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
The bolded line is a fouth column in disp([ . ]) which is supposed to be the entries by dividing two consecutive error respectively i,e., the entries in the third column of disp([ . ]). But what I have is rather the repetition of the third column as the fourth column which I dont want. The more I try fixing it, the more difficulties I face. I really need help which is that the fourth column of disp([ . ]) must be the consecutitive division of entries of the third column. Note that the first entry of the fourth column will be empty, 0 or -, because, there is no entry before the fisrt entry of column three. Thanks in advance! salam mahamahttps://au.mathworks.com/matlabcentral/profile/authors/4478798tag:au.mathworks.com,2005:Question/7175952021-01-15T05:07:00Z2021-01-16T05:23:25Zimporting the excel data into matlab in symbolic math tool i have used symbolic math tool box to find out the variable in the equation. i have imported the data from the excel file to matlab.but i am not getting the result.Sunitha Reddyhttps://au.mathworks.com/matlabcentral/profile/authors/19111554tag:au.mathworks.com,2005:Question/5571192020-06-30T09:00:30Z2021-01-16T05:22:16ZReal-Time error after the last update windows 10Hi,
My Matlab / Simulink after the latest Windows 10 update (19041.329) can't simulate in real time, the error message is:
An error occurred while running the simulation and the simulation was terminated
Caused by:
Error reported by S-function 'sldrtsync' in 'ForcesCompensation_vRo_Ce_Be_Ga_v3/Real-Time Synchronization': Hardware timer cannot be allocated. Real-time kernel cannot run.
Yesterday before the update everything works fine.
I tried to reinstall the following packages:
- Simulink in real time.
- Real-time desktop simulation.
- MATLAB support for the MinGW-w64 C / C ++ compiler.
And reinstall the real-time kernel with "sldrtkernel -install" command.
But the problem was not resolved.
I have the Matlab 2018b and Matlab 2019b and both have the same problem.
Can anyone help me?
Thanks.Alejandro Veigahttps://au.mathworks.com/matlabcentral/profile/authors/9868040tag:au.mathworks.com,2005:Question/7178102021-01-15T10:52:11Z2021-01-16T05:21:17Zsolve non linear equations i wrote the code for non linear equations. But i got the error .can u please tell me how to rectify this error
lear all
close all
syms S J
Qo=26560 %%m3/day
R=0.56
So=220
V=2434.67 %%
X=3000
Ks=0.27
k=1.076
Y=0.39
kd=0.04
bs=0.15
Xf=0.49
Df=1.04
Dw=1.3
L=0.04
a=2.24
bt=kd+bs
Smin=Ks/((Y*k/bt)-1)
Lstar=L*(sqrt(k*Xf/Ks*Df))*Df*Dw
Sstar=S/Ks
jstar=(J/sqrt(Ks*k*Xf*Df))
Sstar_min=(1/(Y*k*(bt-1)))
r=(So-S)/So
eqn1=Qo*(1+R)*(1-r)*(So-S)-a*V*J==0;
eqn2=sqrt((Lstar^1.76)+5.2*(Sstar-Sstar_min)-(Lstar^0.88))/2.6==jstar^0.88;Sunitha Reddyhttps://au.mathworks.com/matlabcentral/profile/authors/19111554tag:au.mathworks.com,2005:Question/7183452021-01-16T04:56:35Z2021-01-16T04:56:35Zcan anyone explain this code?clc; clear all;
k = input('Enter the length of message vector: ');
n = input('Enter the length of codeword: ');
P = input('Enter the Parity Matrix of order k*(n-k): ');
G = [P eye(k)]; %Generator matrix of order k*n
H = [eye(n-k) P']; %Parity check matrix of order n-k*n
t = syndtable(H);
Len = 100000;
m = round(rand(1,Len));
msg = reshape(m,length(m)/k,k);
%C = rem(msg * G,2); %Codewords for message
a1 = 0; a2 = []; a3 = 1; a4 = 1; Sig = [];
for a1 = k:k:length(m)
a2 = mod(m(a3:a1)*G,2);
a3 = a3+4;
Sig(a4:a4+6) = a2;
a4 = a4+7;
end
V = 5; %threshold voltage
V1 = V * m-1;
V2 = V * Sig-1;
snr = 0:1:20;
%% IDEAL SYSTEM
Eb_No=10.^(snr/10); %energy per bit to noise power spectral density ratio
BER_theory=berawgn(Eb_No,'psk',2^k,'nondiff');
%% SYSTEM WITH WHITE GAUSSIAN NOISE
for L = 1:length(snr)
%UNCODED SYSTEM
rx_sig = awgn(V1,snr(L),'measured');
for K = 1:1:Len
if rx_sig(K)>0
a(K)=1;
else
a(K)=0;
end
end
[nErrors,BER_U(L)]=biterr(m,a);
%ENCODED SIGNAL
rx_sig2 = awgn(V2,snr(L),'measured');
for K = 1:1:length(V2)
if rx_sig2(K)>0
b(K)=1;
else
b(K)=0;
end
end
M = decode(b,n,k,'linear',G,t);
[nErrors,BER_C(L)]=biterr(m,M);
end
%% Plotting
figure
semilogy(snr,BER_theory,'-go',snr,BER_U,'-b*',snr,BER_C,'-r*');
xlabel('SNR');
ylabel('BER(log)');
ylim([0.0001 1]);
legend('Theoritical BER','BER of Uncoded Signal','BER of Encoded Signal');
grid on
i placed inputs is k=3 , n=7 and P = [ 1 1 0 ; 0 1 1 ; 1 1 1 ; 1 0 1]Farjad Mehmoodhttps://au.mathworks.com/matlabcentral/profile/authors/20853206tag:au.mathworks.com,2005:Question/7181602021-01-15T20:28:49Z2021-01-16T04:50:49ZHow to plot an edge between two nodes of two different graphs? I'm trying to connect the nodes of graph g (Blue) with the nodes of graph h (Red).
so=[1 1 1 2 2 2 2 3 3 3 5];
ta=[2 3 4 3 4 5 6 6 7 5 7];
g=graph(so,ta);
p=plot(g);
x=p.XData;
y=p.YData;
z2=[0 0 0 0 0 0 0];
subplot(2,2,1);plot(g,'XData',x,'YData',y,'ZData',z2)
s=[1 1 1 2 2 3 3 3 3 4 4 5 5 ];
t=[2 5 6 3 4 7 4 5 6 7 5 7 6 ];
h=graph(s,t);
z=[-3 -3 -3 -3 -3 -3 -3];
hold on; subplot(2,2,1);plot(h,'XData',x,'YData',y,'ZData',z)
Is it something doable?
Thank you all for your continuous support!Asaf McRockhttps://au.mathworks.com/matlabcentral/profile/authors/20274660tag:au.mathworks.com,2005:Question/4575682019-04-20T19:28:25Z2021-01-16T04:40:29ZI get an error, what's wrong? on Sparse matrix logic and answer Write the function for
A sparse matrix is a large matrix with almost all elements of the same value (typically zero). The normal representation of a sparse matrix takes up lots of memory when the useful information can be captured with much less. A possible way to represent a sparse matrix is with a cell vector whose first element is a 2-element vector representing the size of the sparse matrix. The second element is a scalar specifying the default value of the sparse matrix. Each successive element of the cell vector is a 3-element vector representing one element of the sparse matrix that has a value other than the default. The three elements are the row index, the column index and the actual value. *Write a function called "sparse2matrix" that takes a single input of a cell vector as defined above and returns the output argument called "matrix", the matrix in its traditional form. Consider the following run:*
cellvec = {[2 3], 0, [1 2 3], [2 2 -3]};
matrix = sparse2matrix(cellvec)
matrix =
0 3 0
0 -3 0
<</matlabcentral/answers/uploaded_files/215088/Screenshot_20190420-202641~2.png>>
Suraj Tawdehttps://au.mathworks.com/matlabcentral/profile/authors/14922923tag:au.mathworks.com,2005:Question/7182902021-01-16T01:29:21Z2021-01-16T04:36:35ZError using findpeaks Expected Y to be one of these types: double, single Instead its type was table.Hi,
I am trying to read a file and find its peak. But the findpeak function keeps throwing errors. Please help. I am new to matlab.
%clear,clc
readtable('KD.xlsx');
x=qw(:,1);
y=qw(:,2);
%y=data(:,2');
Peaks=findpeaks(ans);
[pks,locs] = findpeaks(KD);
plot(x,y,y(locs),pks,'or')
xlabel('Xvalue')
ylabel('Peak')
axis tight
error message:
Error using findpeaks
Expected Y to be one of these types:
double, single
Instead its type was table.
Error in findpeaks>parse_inputs (line 199)
validateattributes(Yin,{'double','single'},{'nonempty','real','vector'},...
Error in findpeaks (line 136)
= parse_inputs(isInMATLAB,Yin,varargin{:});
Error in Untitled (line 6)
Peaks=findpeaks(ans);Venkatakrishnan Rengarajanhttps://au.mathworks.com/matlabcentral/profile/authors/17562691tag:au.mathworks.com,2005:Question/7183402021-01-16T04:33:49Z2021-01-16T04:33:49Zreplacing loop with cell of index valuesI don't know how to explain with words what I'm trying to do, so here is an example
%I have an array of values
s = [1:100];
% and I have a cell array of different index values
c{1} = 1;
c{2} = 1:5;
c{3} = 2:2:10;
% I would like a cell array t, where
t{1} = s(c{1});
t{2} = s(c{2});
% etc.
% I can do this with a loop, but I'm wondering if there is a way to do this without a loop as my set of indices are large.
Catherinehttps://au.mathworks.com/matlabcentral/profile/authors/1229348tag:au.mathworks.com,2005:Question/7183352021-01-16T04:27:10Z2021-01-16T04:27:10ZHow can I obtain the coordinates(x, y, z) from a 3D isosurface plot?I have written a code to obtain a certain figure using isosurface and isocaps function and now I wish to get all the x, y, z coordinates from it. How can I do this?Idrees Zahidhttps://au.mathworks.com/matlabcentral/profile/authors/12087860tag:au.mathworks.com,2005:Question/7182252021-01-15T22:32:49Z2021-01-16T04:24:02Zmscohere for each frequency band_EEG dataHi all,
I'am working with the following code to get coherence values. I get some values but how can I get the measure for each frequency band? I tried to define F as F=[8.05.13] for alpha and F= [1.0.5.4] for delta. However, I get exactly the same values for alpha and delta. Any help would be greatly appreciated.
ch1= 7 % left electrode
ch2= 48 % right electrode
window = 2*EEG.srate;
nooverlap = 0;
nfft =window*2;
fs= EEG.srate;
F= [8.05.13]% change this for different bands
[Cxy, F] = mscohere (EEG.data(ch1,;),(EEG.data(ch2,;)window, nooverlap,nftt,fs);
belen calvohttps://au.mathworks.com/matlabcentral/profile/authors/19771640tag:au.mathworks.com,2005:Question/7179302021-01-15T13:54:27Z2021-01-16T04:08:17Z"Warning: Unable to find explicit solution. For options, see help."Trying to solve a system of non-linear equations, but I get the above error message.
Here is my code:
clear all
syms h_1 h_2 h_3 h_4 h_5 h_6 l m_1 m_2 m_3 m_4 m_5 m_6
eq1 = h_6*m_1*m_6+2*h_5*m_1*m_5+h_4*m_1*m_4-2*h_6*(m_3)^2-4*h_5*m_2*m_3-2*h_3*m_1*m_3-2*h_4*(m_2)^2-2*h_2*m_1*m_2-h_1*m_1^2+(h_4*h_6-(h_5)^2)*l == 0;
eq2 = 2*h_6*m_2*m_6-4*h_6*m_3*m_5-4*h_4*m_1*m_5-4*h_5*m_3*m_4-2*h_4*m_2*m_4-4*h_2*m_1*m_4-2*h_1*m_1*m_2+(2*h_3*h_5-2*h_2*h_6)*l == 0;
eq3 = -2*h_6*m_3*m_6-4*h_5*m_2*m_6-4*h_3*m_1*m_6-4*h_4*m_2*m_5-4*h_2*m_1*m_5+2*h_4*m_3*m_4-2*h_1*m_1*m_3+(2*h_2*h_5-2*h_3*h_4)*l == 0;
eq4 = h_6*m_4*m_6-2*h_6*m_5^2-2*h_5*m_4*m_5-4*h_3*m_2*m_5-h_4*m_4^2+2*h_3*m_3*m_4-2*h_2*m_2*m_4+h_1*m_1*m_4-2*h_1*m_2^2+(h_1*h_6-h_3^2)*l == 0;
eq5 = -2*h_6*m_5*m_6-4*h_5*m_4*m_6-4*h_3*m_2*m_6-2*h_4*m_4*m_5+2*h_1*m_1*m_5-4*h_2*m_3*m_4-4*h_1*m_2*m_3+(2*h_2*h_3-2*h_1*h_5)*l == 0;
eq6 = -h_6*m_6^2-2*h_5*m_5*m_6+h_4*m_4*m_6-2*h_4*m_3*m_6+2*h_2*m_2*m_6+h_1*m_1*m_6-2*h_4*m_5^2-4*h_2*m_3*m_5-2*h_1*m_3^2+(h_1*h_4-h_2^2)*l == 0;
eq7 = h_1*h_4*h_6-h_2^2*h_6-h_1*h_5^2+2*h_2*h_3*h_5-h_3^2*h_4-1 == 0;
sols = solve([eq1,eq2,eq3,eq4,eq5,eq6,eq7],[h_1, h_2, h_3, h_4, h_5, h_6, l], 'returnconditions', true)
The m_i are known and I need the solution in terms of the m_i. I know there is a solution but I need to confirm as I cannot solve this by hand.
Is this to hard to solve or is my code wrong? Thanks for any helpTatjanahttps://au.mathworks.com/matlabcentral/profile/authors/20821620tag:au.mathworks.com,2005:Question/3587402017-09-28T06:31:26Z2021-01-16T03:51:12ZHow to rotate a body around x-axis in simscape?I have created one wheel model using simscape multibody. I have created a wheel and an axle using body geometry. The axle is along the x-axis and i want to rotate that wheel around x-axis. How to do it? because when i am using revolute joint, then it rotates the body around z-axis. So, which joint should be used to rotate the body around x-axis?shreyas joshihttps://au.mathworks.com/matlabcentral/profile/authors/10860837tag:au.mathworks.com,2005:Question/7176802021-01-15T08:15:15Z2021-01-16T03:49:30ZGPU GTX 1650 TI support
GTX 1650 ti have cuda support. But it is not listed in matlab list of GPU nvidia GeForce why?
CUDA GPUs (NVIDIA)
https://developer.nvidia.com/cuda-gpus
Before close question please update and provide me information.because I want purchase 1650 ti GPU based system and if it will not able to compute matlab then it is waste of money for me .
abhishek singhhttps://au.mathworks.com/matlabcentral/profile/authors/1055295tag:au.mathworks.com,2005:Question/7183002021-01-16T02:04:38Z2021-01-16T03:47:34ZDefine a collection of variablesSuppose I have a table
date visitor city dummy_for_January dummy_for_February dummy_for_March
----------------------------------------------------------------------------------------------------------
I want to define a collection of such dummy variables so that I do not need to write them one by one each time. Please advise. alpedhuezhttps://au.mathworks.com/matlabcentral/profile/authors/10930090tag:au.mathworks.com,2005:Question/7183252021-01-16T03:34:33Z2021-01-16T03:44:38ZSimulink RF Blockset Error: Delay History is Too LongHi,
I am currently modelling an RF system using the RF blockset in Simulink. However, during simulation, I encountered the "delay history is too long" error when trying to use the "variable time delay" block to model the delay for a transmission line. The reason I am not using the "transmission line" block in RF blockset is that it is not tunable (the time delay cannot be varied during simulation).
Currently my delay is set to 1e-9 seconds, I tried values such as 1e-15 seconds but the error is still there. Interestingly, when I remove the variable attenuator and variable phase shifter, the system can simulate just fine.
Here is the error:
Here is the RF Configuration block setup:
Any help is appreciated. Thank you.
Raymond5csema5f31c6https://au.mathworks.com/matlabcentral/profile/authors/11885913tag:au.mathworks.com,2005:Question/7183102021-01-16T02:53:30Z2021-01-16T03:34:47ZMatlab license expiration, now?Now I get this message when I open Matlab:
----------------------------------------------------
Your MATLAB license will expire in 14 days.
Please contact your system administrator or
MathWorks to renew this license.
----------------------------------------------------
Bobby Fischerhttps://au.mathworks.com/matlabcentral/profile/authors/17553780tag:au.mathworks.com,2005:Question/7183202021-01-16T03:28:59Z2021-01-16T03:28:59ZSolving rate equations for multimode laserI wrote a code ( attached) for solving the rate equations (attached) for multimode laser, but with wrong results, any help, please?
function MML
clc; clear
n=3;% Number of modes
tspan=linspace(0,1e-7,10000);%[0 1e-8];
y0=[8.25e5 1e-6 1e-6 1e-6];
[T,Y]= ode45(@(t,y) rate_equation2(t,y,n),tspan,y0);
figure;
plot(T,Y(:,2))
hold on
plot(T,Y(:,3))
hold on
plot(T,Y(:,4))
hold off
figure;
n1=length(T);
Ts=T(n1)/(n1-1); fs=1/Ts;
f=-fs/2:fs/(n1-1):fs/2;f=f/fs;
c=3e8; lambda=980e-9;Vp=3e-12;
F=1; vg=1e10; h=6.63e-34; f1=c/lambda;
Power=F*vg*h*f1*Y(:,1)*Vp*1e3;
y=fftshift(fft(Power));z=log(abs(y));
%m=max(z);
plot(f,z,'b');
%axis([-0.2,0.2,0,0.5]);
xlabel('Notmalized frequency');ylabel('Power (arb. units)')
%xlim([-.08 .08])
T=T*1e9;
figure;
plot(T,(Power),'k');xlabel('Time (ns)');ylabel('Output power (mW)');
figure;
%Stability_window = T/2:T; % Time window with stable dynamics
y = Y(:,1);
L = length(T);
NFFT = 2^nextpow2(L); % Next power of 2 from length of y
Y = fft(y,NFFT)/L;
Y = fftshift(Y);
Y=Y/(max(Y));
lambda=linspace(1546,1554,NFFT);
window = 1000; % Part of spectrum to see
plot(lambda(NFFT/2-window:NFFT/2+window),log(abs(Y(NFFT/2-window:NFFT/2+window))),'b','LineWidth',1)
xlabel('\lambda(nm)')
ylabel('Power (dB)')
set(gca,'FontSize',12,'FontWeight','Bold')
%ylim([-10 1])
return
function dy=rate_equation2(t,y,n)
dy = zeros(n,1);
q=1.6e-19; d=.3e-6; D1=5e-6;L=250e-6;ts=3e-9;c=3e8; ng=4; nr=3.4;eta=.5; N0=8.25e5;
alpha0=2000; lambda0=1310e-9; Dlc=0.845e-9 ; Dld=60e-9;R=0.3;
alpha=alpha0+(1/L)*log(1/R);%J=15e-3;
sum1=0.0;
for i=2:n+1
lambda(i)=lambda0+i*Dlc;
gamma(i)=eta*lambda(i).^2/(4*pi*nr^2*D1*d);
A=(gamma(i)/(eta*ts))*D1*L*d/eta;
D(i)=(Dlc/(pi*Dld))/(1+((lambda(i)-lambda0)/Dld)^2);
g(i)=eta*(ng/c)*A*(D(i)*y(1)-N0);
sum1=sum1+g(i).*y(i);
end
J=.00001;
for i=2:n+1
dy(1)=J/(q*d)-y(1)/ts-c/(eta*ng)*sum1;
dy(i)=(gamma(i)/ts).*(D(i)*y(1))+(c/ng)*(g(i)-alpha).*y(i);
end
returnHassan Sultanhttps://au.mathworks.com/matlabcentral/profile/authors/7548425tag:au.mathworks.com,2005:Question/7175002021-01-14T23:46:13Z2021-01-16T03:16:21ZHow do I present an audio signal in a time domain plot using MATLAB, such that the y-axis is in decibel (dB) instead of of a linear scale?Please, I have a recorded audio signal from experimental work. I have been able to plot the time domain graph (see attached) using Matlab software. By default, the y-axis values are present in a linear scale (Amplitude). I would like to plot the time domain graph such that the y-axis scale is is in decibel. I understand that using 20*log10(signal/ref. signal) should provide the decibel scale on the y-axis, however, this does not seem to work after several attempts.
** My code**
Let say the signa name is TD, so I use the code plot(20*log10(TD/20*10^-6)), the 20*10^-6 is my reference air pressure. The problem is that the entire signal is distorted.
Please, I would be glad if someone can assist me (specifically with a code in matlab to visualise the signal). I might not be doing something right. Thank you.
Thank you.Kwaku Owusuhttps://au.mathworks.com/matlabcentral/profile/authors/18605085tag:au.mathworks.com,2005:Question/5407072020-06-02T04:00:00Z2021-01-16T02:37:18ZWhy does MATLAB fail to install with a "'std::runtime_error' what(): Unable to launch the MATLABWindow application" error on Linux?When I try to install MATLAB it fails with the following error:
terminate called after throwing an instance of 'std::runtime_error'
what(): Unable to launch the MATLABWindow application
AbortedMathWorks Support Teamhttps://au.mathworks.com/matlabcentral/profile/authors/4622813tag:au.mathworks.com,2005:Question/7183052021-01-16T02:23:59Z2021-01-16T02:23:59ZRecovery app designer fileI had an abrupt close of app designer and lost the file that I am working and the program recovered an old versión of this app. There is some way to recover the newest version?
ThanksUnivallehttps://au.mathworks.com/matlabcentral/profile/authors/4013302tag:au.mathworks.com,2005:Question/7182752021-01-16T00:55:51Z2021-01-16T02:01:21ZUse arrayfun and cellfun to avoid for-loopsHey there,
I am currently getting used to all the functions provided by MATLAB, so I am unfortunately not entirely sure how to fully utilize cellfun and arrayfun.
I was wondering, whether there are faster workarounds for for-loops, e.g.
for i= 1:length(Categories)-1
for j= i+1:length(Categories)
% separated_data is a 3D array of data, I want to get the p-Values for the data matching
% several numerated categories here
p=vertcat(p,[i,j,ranksum(separated_data(:,1,i),separated_data(:,1,j)),...
ranksum(separated_data(:,2,i),separated_data(:,2,j)),ranksum(separated_data(:,3,i),separated_data(:,3,j))]);
end
end
Another one would be a routine I am trying to write to more conveniently import my data (I know there are a lot of workarounds, but I am writing my own for practice and to meet the special formatting of my data). Here's my plan:
Get the file name (done)
Obtaining the header titles and enumerating them, then ask the user to give a vector with the columns they want to import (done)
Create a cell array by repmat({'%*f'},1,max(input_vector)) (done)
Now I want to remove the asterisks for all the elements given in the input_vector
I have tried using cellfun and arrayfun, but once again I am not familiar enough with them to get it to work without a for-loop. Therefore, here is my current code for that issue:
columns = input('Enter which columns you''d like to import as a vector:\n');
format = horzcat(repmat({'%*f'},1,max(columns)),{'%*[^\n]'});
for i = 1:length(columns)
format{i} = erase(format{i},'*');
end
I'd be grateful for any advice related to the given problems, but also if you know a more detailed description of cellfun, arrayfun and these things (helping to optimize resources, runtime, etc.) than provided by
doc cellfun
doc arrayfun
Thanks in advance!Jannis Kornhttps://au.mathworks.com/matlabcentral/profile/authors/17428521tag:au.mathworks.com,2005:Question/7182602021-01-16T00:14:44Z2021-01-16T01:53:07Zfmincon for bounded optimization problemHello,
I am trying to solve a nonlinear optimization problem using fmincon interior point method. Originally my problem formulation does not have bounds on the decision variable, and when i try to run it without the bounds then it takes infintie time and when I run it with bounds then it is much faster. Following are my questions:
1) Why bounds are making the algorithm faster?
2) The final optimal result for the problem is nowhere near the bound, but my lagrange multiplier for the bounds is coming to be non zero, arent they supposed to be zero if the solution is not hitting the bounds?
3) How is the first order optimality criteria defined for interior point method? I saw the documentation but it is not clear to me, is the infinite norm of the grad or some other equation?
I am giving very good initial guess (exact true values) to my problem to make sure it is near the optimal. When I do that, the optimizer is just giving me the intial guess as my final solution which is not possible as I am feeding noisy data to my problem.
Thanks in advanceDevyanihttps://au.mathworks.com/matlabcentral/profile/authors/5399877tag:au.mathworks.com,2005:Question/7182952021-01-16T01:52:22Z2021-01-16T01:52:22Zhow to find coordinate of a puzzle piece?I try to determine the coordinates of a puzzle piece on the original image using the normxcorr2 function. Then I draw a rectangle on the correspondence of the two elements. Unfortunately, I notice that the coordinates that this match has given me are not good. Could someone have an idea how to improve the use of this feature and get some better results.
The puzzle piece has the name "cpiece" and the original picture has the name "bild"
clear all;
close all;
clc
cpiece = im2gray(imread('cpiece1.jpg'));
bild = im2gray(imread('original.jpg'));
figure(1)
montage({bild,cpiece})
c = normxcorr2(cpiece,bild);
figure(2)
surf(c)
shading flat
[ypeak,xpeak] = find(c==max(c(:)));
yoffSet = ypeak-size(cpiece,1);
xoffSet = xpeak-size(cpiece,2);
figure(3)
imshow(bild)
drawrectangle(gca,'Position',[xoffSet,yoffSet,size(cpiece,2),size(cpiece,1)],'FaceAlpha',0);Tiodong Nongni Gilles Patrickhttps://au.mathworks.com/matlabcentral/profile/authors/20713099tag:au.mathworks.com,2005:Question/7182852021-01-16T01:26:14Z2021-01-16T01:44:38ZIssue with vectors being the same lengthMy code seems to be having a problem with plotting. I've even tried using linspace to 'fix' xx and Vz1 but that didn't seem to work. Any suggestions would be much appreciated
Error message:
Error using plot
Vectors must be the same length.
Error in Example2 (line 244)
plot(xx,Vz1,'b-','LineWidth',2);
Lines of code to fix:
Defining xx:
xa = 0;
xb = 20;
xc = 40;
x1 = linspace(xa,xb,nn)';
x2 = linspace(xb,xc,nn)';
xx=[x1;x2];
Defining Vz1:
Vz1 = 0*ones(nn,1);
Vz2 = 0*ones(nn,1);
Vz=[Vz1;Vz2];Rebekah Kuehlhttps://au.mathworks.com/matlabcentral/profile/authors/15589988tag:au.mathworks.com,2005:Question/7182802021-01-16T01:23:58Z2021-01-16T01:35:06ZPlease write the c-code below in matlab.#include<stdio.h>
int main()
{
const int MAX = 1000;
char number[MAX+1];
int index;
int j;
for(index = 0; index <= MAX; index++)
{
number[index]=1;
}
for(index = 2; index
<= MAX; index++)
{
if(number[index]==1)
{
for(j=2*index; j<=MAX; j=j+index)
{ number[j]=0;
if(index%2==0)
number[j]=0;
else
if(index%3==0)
number[j]=0;
else
if(index%5==0)
number[j]=0;
else
if(index%7==0)
number[j]=0;
}
}
}
printf("The following numbers are prime:\n");
for(index=2;
index<=MAX; index++)
{
if(number[index]==1)
printf("%d\n",index);
}
return 0;
}Attcharapan Chailerthttps://au.mathworks.com/matlabcentral/profile/authors/20741863tag:au.mathworks.com,2005:Question/7181252021-01-15T19:44:36Z2021-01-16T01:33:08ZPlot a 3d domain with colors determined by 3d arrayI have 3 vectors: X(N), Y(N), Z(N) that define a space in 3D, let's call it D = [X(1),X(N)] x [Y(1),Y(N)] x [Z(1),Z(N)]. I have a matrix with values at each point in D, called out(N,N,N). How can I plot the space D as points with colors determined by the values given in out(N,N,N)?Michael Hennesseyhttps://au.mathworks.com/matlabcentral/profile/authors/9776176tag:au.mathworks.com,2005:Question/6514032020-11-17T21:01:41Z2021-01-16T01:31:31Zhow to plot the mean of values from swept dataHi everyone,
I have a array of data where I ramped one variable and measured another a number of times. I would like to find the average of the independent variable at each data point in order to plot this. Does anyone have any suggestions on how I could do this?
Cheers!
EmEmhttps://au.mathworks.com/matlabcentral/profile/authors/7295000tag:au.mathworks.com,2005:Question/4669712019-06-13T17:50:01Z2021-01-16T01:25:27ZIf else problem for yearWrite a function called valid_date that takes three positive integer scalar inputs year, month, day. If these three represent a valid date, return a logical true, otherwise false. The name of the output argument is valid. If any of the inputs is not a positive integer scalar, return false as well. Note that every year that is exactly divisible by 4 is a leap year, except for years that are exactly divisible by 100. However, years that are exactly divisible by 400 are also leap years. For example, the year 1900 was not leap year, but the year 2000 was.
valid = valid_date(2018,4,1)
valid = valid_date(2018,4,31)RAHUL ANTILhttps://au.mathworks.com/matlabcentral/profile/authors/14839405tag:au.mathworks.com,2005:Question/7182352021-01-15T22:40:09Z2021-01-16T01:10:58ZSimulink on M1 macbookDoes the rosetta 2 support simulink on the m1 macbook ?Muhamad Ariff Sanihttps://au.mathworks.com/matlabcentral/profile/authors/17634415tag:au.mathworks.com,2005:Question/7163982021-01-13T22:19:07Z2021-01-16T01:10:17ZHelp fitting data to an implicit equationHello:
I need to fit some data to the following implicit equation:
((1-y)^(1-b)/y)=exp(-kt)
t is a vector containing time values and y is a vector containing current values. for each series of data y vs t, I need to determine b and k
b has to be between 0 and 1, and k needs to be greater than 0.
I have both the optimization and the curve fitting toolboxes.
Any suggestions on what tools to use (lsqcurvefit? something else? would be very appreciated)
Thanks!mura0087https://au.mathworks.com/matlabcentral/profile/authors/20323560tag:au.mathworks.com,2005:Question/7182552021-01-15T23:55:11Z2021-01-16T01:03:49ZHow rotate a cylinder?Hi everyone,
I have a matrix A [100x3] which represents the coordinates of a cilinder oriented in the space. I have calculated the center of this cylinder by doing C=Mean(A).
My question is how can i rotate the cylinder in order to have origin of the xyz axis in the point C?
Any help would be appreciated,
LorenzoLorenzo Bennatihttps://au.mathworks.com/matlabcentral/profile/authors/20417281tag:au.mathworks.com,2005:Question/7182502021-01-15T23:14:12Z2021-01-16T00:53:00ZFunctions in If StatementsI have two versions of code separated by an if statement. The if statement checks the version of Matlab that the user is running and executes based on that. So the two versions of code are incompatible with the other version, so I have to put each block of code in a function. Here's my problem: I have no idea how to properly execute the function in the main program. Here is some example code
Main Block of code
v= ver('MATLAB');
if v.Release =='(R2012a)'
for n= 1:FMn %cycle through files in the directory
finalname = FMdir(n).name;
end
start = 1; %start at one
out = n; %stop at the last file in the folder
for k = start:out
FM = FMdir(k).name;
InM = InMdir(k).name;
ProcessFilesOld(FM, InM, k) %FUNCTION
%more code
end
elseif v.Release=='(R2019b)'
for n= 1:FMn %cycle through files in the directory
finalname = FMdir(n).name;
end
start = 1; %start at one
out = n; %stop at the last file in the folder
for i = start:out
num_strfinal = num2str(i, '%02.f'); %cast the number as a string (make the format be 0#)
number = string(num_strfinal);
FM = dir(fullfile(filepath,'Processfiles\*FM')+ number + '_*.ep'); %Pull out the final measurement file being used
FinalM = getfield(FM, 'name'); %pull out and save the name field
IN = dir(fullfile(filepath,'Processfiles\*InM')+ number + '_*.ep'); %Pull out the initial measurment file being used
InitialM = getfield(IN, 'name'); %pull out and save the name field
ProcessFilesNew(FinalM, InitialM) %FUNCTION
%
% More code
end
end
Example of ProcessFilesNew code
function [Final,Initial,Difference,serial ] = ProcessFilesNew(FinalM, InitialM )
opts = detectImportOptions(FinalM, 'FileType','text'); %Set the file type as a text
opts.DataLines = [1, Inf]; %Start at one and go through the entire document, regardless of length
opts.Delimiter = ','; %look for 2 column data
opts.VariableNames = ['Frequency', 'Magnitude']; %Label x-axis and y-axis
opts.VariableTypes = ["double", "double"]; %Import data as doubles
opts.ImportErrorRule = "omitrow"; %If data isn't double then ignore row
opts.MissingRule = "omitrow"; %If data is missing, ignore row
opts.ExtraColumnsRule = "ignore"; %Ignore extra columns
opts.EmptyLineRule = "read";
Final = readtable(FinalM, opts);
%% REPEAT THIS CODE BUT FOR InitialM
If you need more code let me know, I figured you wouldn't appreciate sifting through 140 lines if you didn't need it.
Please help me figure out how to make the functions work, thank youNat Personhttps://au.mathworks.com/matlabcentral/profile/authors/20731547tag:au.mathworks.com,2005:Question/2646642016-01-21T15:36:49Z2021-01-16T00:30:12Zhow to customize dvbs2ldpc in matlabI want to use dvbs2ldpc but length of http://www.mathworks.com/help/comm/ref/comm.ldpcencoder-class.html#bsyh0xo-4
but it has a problem about length of data
how should i customize length of this program regarding my own code and adopt it with my program ?
i found another sample here also
http://www.mathworks.com/help/comm/examples/dvb-s-2-link-including-ldpc-coding.htmlHamid Reza Barzegarhttps://au.mathworks.com/matlabcentral/profile/authors/6085600tag:au.mathworks.com,2005:Question/7176202021-01-15T06:30:59Z2021-01-16T00:12:02ZCorrelation of rows of matrix B with rows of reference matrix AI have a reference matrix A (10000 x 400) and a matrix B (10000 x 400).
I need to compare the first row of B to all the rows of A. I know the rest of the rows of B are going to be nearby (+/- 10) to what it found the strongest correlation for the first row. To make it more challenging, the row of B could shift in columns to get a higher correlation.
I started the following but i'm not sure if I'm in the right path as far as functions nor my results!
I need to get B to match A row by row and for it to be able to shift in columns if needed to achieve the highest correlation. And just getting the yshift and xshift of each row of B.
[r,c]=size(matA);
for i=1:r
x=crosscorr(matA(i,:),matB(i,:))
endWookiehttps://au.mathworks.com/matlabcentral/profile/authors/8799484tag:au.mathworks.com,2005:Question/5560242020-06-28T10:27:32Z2021-01-16T00:05:36ZWhat frustrates you about MATLAB? #2Similar to what has happened with the wishlist threads (#1 #2 #3 #4 #5), the "what frustrates you about MATLAB" thread has become very large. This makes navigation difficult and increases page load times.
So here is the follow-up page.
What should you post where?
Wishlist threads (#1 #2 #3 #4 #5): bugs and feature requests for Matlab Answers
Frustation threads (#1 #2): frustations about usage and capabilities of Matlab itself
Missing feature threads (#1 #2): features that you whish Matlab would have had
@anyone posting a new thread when the last one gets too large (about 50 answers seems a reasonable limit per thread), please update this list in all last threads. (if you don't have editing privileges, just post a comment asking someone to do the edit)Rikhttps://au.mathworks.com/matlabcentral/profile/authors/3073010tag:au.mathworks.com,2005:Question/1229112014-03-24T18:43:37Z2021-01-16T00:04:16Zfmincon interior point stopping criteriaGreetings,
# MY PROBLEM)
I'm using fmincon's interior point algorithm. I want to stop the computation if the distance f(x_k) - f(x_opt) <= epsilon where x_opt is the optimum and x_k is the point generated by the algorithm at iteration k.
# MY TRIALS)
I'm seaching for an option to stop computation when the 'mu' of the problem
min f(x) - mu (sum BarrierFunctions(x))
is less than a fixed parameter but I don't have found nothing.
I've read the documentation on the stopping criterias, TolFun doesn't seems to do what I want and the only things that refers to the 'mu' is the starting value.
Thanks for your help.R Lhttps://au.mathworks.com/matlabcentral/profile/authors/4996481tag:au.mathworks.com,2005:Question/980502012-09-10T15:55:00Z2021-01-16T00:04:16ZWhy do I get an error saying "Undefined function or variable 'matlabrc'" when executing a program that uses a MATLAB-compiled shared library?I am trying to use a MATLAB-compiled shared library in a C++ program. There are no issues when I use the same code with the libraries compiled using MATLAB Compiler 4.7 (R2007b). However, when I recompile all the MATLAB libraries using MATLAB Compiler 4.9 (R2008b) and then try to execute the same program, the <libName>Initialize() function fails with the following error:
??? Undefined function or variable 'matlabrc'
MathWorks Support Teamhttps://au.mathworks.com/matlabcentral/profile/authors/4622813tag:au.mathworks.com,2005:Question/4519772019-03-24T04:07:32Z2021-01-16T00:00:34ZAdd echo to audio signal in matlabWrite a function called echo_gen that adds an echo effect to an audio recording. The function is to be called like this:
output = echo_gen(input, fs, delay, amp);
where input is a column vector with values between -1 and 1 representing a time series of digitized sound data. The input argument fs is the sampling rate. The sampling rate specifies how many samples we have in the data each second. For example, an audio CD uses 44,100 samples per second. The input argument delay represent the delay of the echo in seconds. That is, the echo should start after delay seconds have passed from the start of the audio signal. Finally, amp specifies the amplification of the echo which normally should be a value less than 1, since the echo is typically not as loud as the original signal.
The output of the function is a column vector containing the original sound with the echo superimposed. The output vector will be longer than the input vector if the delay is not zero (round to the nearest number of points needed to get the delay, as opposed to floor or ceil). A sound recording has values between -1 and 1, so if the echo causes some values to be outside of this range, you will need to normalize the entire vector, so that all values adhere to this requirement.
MATLAB has several sample audio files included that you can try: splat, gong, and handel are a few examples. Try the following:
load gong % loads two variables, y and Fs
sound(y, Fs) % Outputs sound Priyamvada Shankarhttps://au.mathworks.com/matlabcentral/profile/authors/15104143tag:au.mathworks.com,2005:Question/3705282017-12-01T23:32:22Z2021-01-15T23:59:12ZControlling the color of crosshair raised by ginputHello, I need to use ginput. It "raises raises crosshair in the axes" - which is fine. Unfortunately, this crosshair is black, and in the axes where I need this function the background is, usually, black too, so the crosshair is very difficult to see. Changing background is not really an option. Until now I used an old version of Matlab, where this crosshair was drawn in XOR mode, and therefore this problem did not appear. Now i am forced to upgrade to the most current version, and now the XOR is banished by Mathworks. This creates problems in the described use case, but also in other use cases. Any ideas will be greatly appreciated.
Thank you,
Naum DerzhiNaum Derzhihttps://au.mathworks.com/matlabcentral/profile/authors/1376471