https://nl.mathworks.com/matlabcentral/answers/questionsMATLAB Answers — New Questions2019-12-06T01:41:07Ztag:nl.mathworks.com,2005:Question/4951382019-12-06T01:41:07Z2019-12-06T01:41:07ZI keep getting the error "Array indices must be positive integers or logical values?"I have been editing a code I found that models a 2 cart system using Euler's Method in an attempt to make it a 3 cart system. However, on line 63 I am recieving an error that states "Array indices must be positive integers or logical values." I am not sure what this means or how to fix it. Any help would be apprecieted. Thanks!
William Van Beekhttps://nl.mathworks.com/matlabcentral/profile/authors/16057501-william-van-beektag:nl.mathworks.com,2005:Question/4951202019-12-05T22:48:52Z2019-12-06T01:24:11Zpolyfit and polyval problemHi there,
I am trying to plot a line using the ployfit and command
x and y are the coordinates in attached xy the plot.
I can't plot a polyfit curve that reproduces the original.
I alway came up with something different from the original curve.
Paul Rogershttps://nl.mathworks.com/matlabcentral/profile/authors/16600209-paul-rogerstag:nl.mathworks.com,2005:Question/4951362019-12-06T01:23:24Z2019-12-06T01:23:24Zregistering and image help (temperature detection from eyes)I have a project where I am registering and image using and infrared camera and a webcam. I have followed the article https://www.mathworks.com/company/newsletters/articles/automating-image-registration-with-matlab.html
But with updates it is no longer the same. I am stuck on the part after calculating the temperature. I cannot get the picture to appear with the text because I get various error codes and have tried a lot already. Please help!!
<<
<</matlabcentral/answers/uploaded_files/253108/image.jpg>>
>>
Marlene Gonzaleshttps://nl.mathworks.com/matlabcentral/profile/authors/16996860-marlene-gonzalestag:nl.mathworks.com,2005:Question/4949202019-12-05T00:51:12Z2019-12-06T01:15:23Zplot with input argumentsi want to subplot 4 string containg cell array from ( sin, cos, tan,sinh) and vector (+,o,*,x,s) and the mathmatical function should be ploted in interval (-2pi,2pi)with step 0.3Roger Nadalhttps://nl.mathworks.com/matlabcentral/profile/authors/16935264-roger-nadaltag:nl.mathworks.com,2005:Question/4950192019-12-05T12:46:58Z2019-12-06T01:14:20ZWhy the 'ismembertol' function fails on this 5 lines code?Tried to run this code
bb = [20 10
NaN NaN];
aa = [20 8
20 10];
[LIA,LOCB] = ismembertol(aa, bb,'ByRows', true);
But the following unexpected result was acquired.
LIA =
2×1 logical array
0
0
Then, if I revise matrix 'aa', and run the following code again, reasonable result can be get.
bb = [20 10
NaN NaN];
aa = [20 10];
[LIA,LOCB] = ismembertol(aa, bb,'ByRows', true);
>> LIA =
logical
1
Any corrections? Thank you!
Jiejie wuhttps://nl.mathworks.com/matlabcentral/profile/authors/4290332-jie-wutag:nl.mathworks.com,2005:Question/3810972018-02-06T15:11:41Z2019-12-06T01:13:39ZCompare two tables with two column combinationsI have two tables, say:
t1 = table(categorical({'a';'b';'c';'c';'a';'b'}),categorical({'d';'e';'d';'f';'e';'d'}),[1;2;3;4;5;6],datetime({'2017-1-1 12:00 AM','2017-1-3 10:20 AM','2017-1-3 1:36 PM','2017-1-4 9:45 AM','2017-1-6 12:00 AM','2017-1-7 12:12 PM'})')
t2 = table(categorical({'a';'a';'c';'b';'c'}),categorical({'f';'d';'e';'f';'d'}),[5;4;3;2;1],datetime({'2017-1-1 12:00 AM','2017-1-3 6:20 AM','2017-1-3 1:36 PM','2017-1-4 9:45 AM','2017-1-6 12:10 AM'})')
t1 =
6×4 table
Var1 Var2 Var3 Var4
____ ____ ____ ____________________
a d 1 01-Jan-2017 00:00:00
b e 2 03-Jan-2017 10:20:00
c d 3 03-Jan-2017 13:36:00
c f 4 04-Jan-2017 09:45:00
a e 5 06-Jan-2017 00:00:00
b d 6 07-Jan-2017 12:12:00
t2 =
5×4 table
Var1 Var2 Var3 Var4
____ ____ ____ ____________________
a f 5 01-Jan-2017 00:00:00
a d 4 03-Jan-2017 06:20:00
c e 3 03-Jan-2017 13:36:00
b f 2 04-Jan-2017 09:45:00
c d 1 06-Jan-2017 00:10:00
Now I want the result or the rownumbers of every combination of the first two columns in t2 that are not in t1
How can I do this?
*Edited question with a little more complicated tableAletta Wilbrinkhttps://nl.mathworks.com/matlabcentral/profile/authors/6908880-aletta-wilbrinktag:nl.mathworks.com,2005:Question/4951352019-12-06T01:06:47Z2019-12-06T01:09:14ZSTROOP TEST- COGENT Hi,
a) how do create a stroop test to randomise the colour of the word. e.g. the word 'RED' with a blue/green/white font colour
b) i am also interested in randomising the colour of a square
i have the codes to display the word and the 2 squares below it but how do i get it to run with varying colours throughout the experiment in a randomised order?
any help would be much appreciated and many thanks in advanceTanitoluwa Femi-Idowuhttps://nl.mathworks.com/matlabcentral/profile/authors/16451453-tanitoluwa-femi-idowutag:nl.mathworks.com,2005:Question/4951022019-12-05T20:20:25Z2019-12-06T01:08:25Z90 degree phase shift Hi,
I am using the vary phase of signal during simulation (https://www.mathworks.com/help/simrf/ug/variable-phase-shift.html), when I open the MATLAB command, the example shown works with the phase varying 180 degree. But when I change the simulink control signal into 90 degree, the output becomes into a straight line rather than 90 degree phase shift.
I was wondering if someone knows how to fix this problem or some other ways of doing the 90 degree phase shift.
Thanks Yuntian Luohttps://nl.mathworks.com/matlabcentral/profile/authors/14094486-yuntian-luotag:nl.mathworks.com,2005:Question/3906392018-03-25T23:47:41Z2019-12-06T01:02:25ZHow to address server and multiple clients communicate using tcpip function? t = tcpip(0.0.0.0,3000,'NetworkRole','server');
fopent(t) --server is open for connection
t = tcpip('localhost',3000,'NetworkRole','client');
fopent(t) --client connects to server from other instance of matlab
But, only one client is able to connect, how can we make multiple instances to connect with server?vishal reddy banalahttps://nl.mathworks.com/matlabcentral/profile/authors/10751885-vishal-reddy-banalatag:nl.mathworks.com,2005:Question/2460452015-09-30T11:19:29Z2019-12-06T01:00:53ZDoes Matlab / Simulink support HackRF SDR ?Does Matlab support the HackRF Software Defined Radio ? It has support for Ettus Radio and SDR-RTL dongles.William Sutherlandhttps://nl.mathworks.com/matlabcentral/profile/authors/5343789-william-sutherlandtag:nl.mathworks.com,2005:Question/4951342019-12-06T00:57:15Z2019-12-06T00:57:15ZDiscrete optimization using fmincon, ga()Hi Every one
My objective function consists of 4 variables f(x,Ppv,PLoad,Price). Here, the size of Ppv, PLoad, Price are 1x144 and they are known to me. I need to find x which is also 1x144 of size, so that my objective function value is minimum. I have some non linear constraints as well.
I have used fmincon
x = fmincon(objective,x0(1:144),A,b,Aeq,beq,lb,ub,nonlincon,options);
I also used genetic algorithm
x = ga(objective,144,A,b,Aeq,beq,lb,ub,nonlincon);
## In case of fmincon, when the program terminates it says that, fmincon stopped because it exceeded the function evaluation limit. Changing the options.MaxFunctionEvaluations does not help. But in the output, some constraints are not satisfied.
## In case of ga(), when the program terminates it says that, Optimization terminated: no feasible point found. The output is really bad compared to fmincon.
Please suggest me a solution of my problem.A M Mahfuz Ur Rahmanhttps://nl.mathworks.com/matlabcentral/profile/authors/12670571-a-m-mahfuz-ur-rahmantag:nl.mathworks.com,2005:Question/4951332019-12-06T00:49:56Z2019-12-06T00:49:56ZSpecify the FFT form of x [n] = {0, 1, 2, 3, 3, 2, 1, 0} with FFT DIT!Specify the FFT form of x [n] = {0, 1, 2, 3, 3, 2, 1, 0} with FFT DIT!Hinggar Trusthihttps://nl.mathworks.com/matlabcentral/profile/authors/11057429-hinggar-trusthitag:nl.mathworks.com,2005:Question/4951302019-12-06T00:27:54Z2019-12-06T00:47:24ZHow to find index of rows without -999I have a super long matrix like the below:
-5, 25, 35
-999, 8, 12
5, 7, 16
8, 9, -999
-999, -999, -999
22, 3, -999
How do I find the rows without any -999 (rows # 1 and 3 in this case) without writing a loop?
Thanks.
Leonhttps://nl.mathworks.com/matlabcentral/profile/authors/3133287-leontag:nl.mathworks.com,2005:Question/4951272019-12-06T00:07:39Z2019-12-06T00:46:48ZSpeed up nested for loopHi,
I am looking for ways to speed up the nested for loop below, but am having trouble working out how- I have tried to vectorise with meshgrid but this didn't seem to work greatly.
for ix=2:nx-1
for jy=2:ny-1
phinew(ix,jy)=0.5*1/((dx^2)+(dy^2))*((dy^2)*(phiold(ix+1,jy)+phiold(ix-1,jy))+(dx^2)*(phiold(ix,jy+1)+phiold(ix,jy-1)));
end
end
nx and ny are both = 100, and phinew and phiold are 100x100 doubles. Dy and Dx are related to lengths input by the user.Peter Foxhttps://nl.mathworks.com/matlabcentral/profile/authors/14682236-peter-foxtag:nl.mathworks.com,2005:Question/4951162019-12-05T22:20:49Z2019-12-06T00:44:08Zcalling mex function from Simulink I have a mex-fille build from C. I want to use it in Simulink but do I need to re write a S-function? I have tried to call without success a Matlab function.Frederic Fourmauxhttps://nl.mathworks.com/matlabcentral/profile/authors/14796130-frederic-fourmauxtag:nl.mathworks.com,2005:Question/4951322019-12-06T00:42:22Z2019-12-06T00:42:22ZRemove periodic Noise and convert photo to RGB again Here i have an image with periodic noise and i want to convert it to frequency domain using Fourier transform and apply notch filter to remove noise and then inverese fourier transform to get image to spatial domain again and convert it to RGB image again. Here is my code for that but i just convert image to frequence domain and apply filter but doesn't work and after that inverese fourier transform to convert image to spatial domain but can't convert it to RGB and just saw image without colors.
f = im2double(rgb2gray(imread('Moire2.bmp')));
imshow(f), title('Original Image');
F = fft2(f);
%create filter for noise removal but doesn't work and need changes
H = ones(size(f));
x = 10;
H(165-x:169+x, 127-x:131+x) = 0;
H(170-x:174+x, 61-x:65+x) = 0;
H = ifftshift(H);
% apply your own filter to image
filtered = F .* H;
figure, imshow(filtered) , title('Filter');
% inverse fourier trensform to restore image to spatial Domain again and i want to convert it to RGB image but can't do that
f1 = ifft2(filtered);
figure, imshow(f1), title('Restored Image'); Ahmed Emadhttps://nl.mathworks.com/matlabcentral/profile/authors/16264900-ahmed-emadtag:nl.mathworks.com,2005:Question/4951292019-12-06T00:26:35Z2019-12-06T00:42:19ZTrying to have user input names into matlab and store them in a matrixI am working on a project where I can input names and have them stored in a matrix or vector, but keep getting this error.
"Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
Error in Cy_Young_Program (line 4)
pitcher_prompt(pn) = input('Input Pitcher Name: ',"s")"
Here is the code I am using...
injury_prob = rand;
%Code for inputing different pitchers names
for pn = 1:3
pitcher_prompt(pn) = input('Input Pitcher Name: ',"s")
%ppm()
end
Christian Resslerhttps://nl.mathworks.com/matlabcentral/profile/authors/16048463-christian-resslertag:nl.mathworks.com,2005:Question/4951312019-12-06T00:32:59Z2019-12-06T00:32:59Zdetect Circles and squares on the image using regionprops Now , i have image called "test.png" and my question is how to detect circles with & without holes and display each of them in single figure and here is my code but desn't work with me , so need help
I = imread('test.png');
imshow(I);
I = rgb2gray(I);
I = im2bw(I,0.01);
[L ,num] = bwlabel(I);
stats1 = regionprops (L,'EulerNumber' , 'Area' , 'Perimeter' , 'BoundingBox');
sum = 0;
for R=1:num
% this way desn't work but maybe it just need a little changes
% x = uint8 (stats1(R).BoundingBox(1));
% y = uint8 (stats1(R).BoundingBox(2));
% if (I(x,y) == 0)
% sum = sum + 1;
% bb = stats1(R).BoundingBox;
% rectangle('position',bb,'edgecolor','r','linewidth',1.3);
% end
circularity = (stats1(R).Perimeter .^ 2) ./ (4 * pi * stats1(R).Area);
if (circularity >= 1.1)
sum = sum + 1;
bb = stats1(R).BoundingBox;
rectangle('position',bb,'edgecolor','r','linewidth',1.3);
end
end
disp(sum);
Ahmed Emadhttps://nl.mathworks.com/matlabcentral/profile/authors/16264900-ahmed-emadtag:nl.mathworks.com,2005:Question/4951282019-12-06T00:26:18Z2019-12-06T00:29:55ZUse the DFT to analyse the spectral content of this signal. Let x(t) = cos(2πf1 t) + cos(2πf2 t) be a continuous-time signal with f1 = 0.22 Hz and f2 = 0.34 Hz. Iyappan namachivayamhttps://nl.mathworks.com/matlabcentral/profile/authors/16928688-iyappan-namachivayamtag:nl.mathworks.com,2005:Question/1646102014-11-28T08:28:33Z2019-12-06T00:26:17Zdelete line plot via handles not workingHi, I am plotting a histogram and want to draw a line that represents the mode:
bar(x,counts,'b','EdgeColor','b');
xm=mode(IM(:));
Now as I will want to replot this linen with a slider callback later, and wont want to have to
replot the barchart, I thought adding the line plot here using handles, would then allow me to delete it later and replot it (whilst keeping the barchart still present)
So to plot the line using handles (on my axes component)
AxesH = axes(handles.axes5);
LineH=plot([xm xm],[0 max(counts)],'r', 'LineWidth',1); %draw line representing the mode (most frequent)
set(AxesH, 'UserData', LineH); %save so can recall or delete later
guidata(hObject, handles);
Then under a slider callback, firstly I want to delete the current line:
OldLineH = get(handles.axes5, 'UserData');
delete(OldLineH);
and then plot the new one based on the slider value
LineH=plot([x(p) x(p)],[0 max(counts)],'r', 'LineWidth',1);
guidata(hObject, handles);
drawnow;
hold on;
But its not deleting the first one, so I get an accumulation of lines.
<</matlabcentral/answers/uploaded_files/21823/img26.png>>Jasonhttps://nl.mathworks.com/matlabcentral/profile/authors/1217570-jasontag:nl.mathworks.com,2005:Question/4951122019-12-05T21:31:09Z2019-12-06T00:24:10Zindex variable based on time pointsi have a variable with 1400 images stored in it. I want to index this loop into 40 time points, (so there are 40 variables each containing 35 frames)
mri % 128 x 128 x 1400 uint16
I am trying to build a loop that for each instance in the loop (t = 40), 35 frames are stored into an output variable so essentially at the end I could have an output variable which is
output % 128 x 128 x 35 frames x 40 timepoints
%here is the rudimentary code that I am working from to build into a for loop
perf_0 = mri(:,:,1:35);
perf_1 = mri(:,:,36:70);
perf_2 = mri(:,:,71:105);
perf_3 = mri(:,:,106:140);
perf_4 = mri(:,:,141:175);
perf_5 = mri(:,:,176:210);
perf_6 = mri(:,:,211:245);
Raheema Al Karim Damanihttps://nl.mathworks.com/matlabcentral/profile/authors/15751635-raheema-al-karim-damanitag:nl.mathworks.com,2005:Question/4950432019-12-05T15:26:07Z2019-12-06T00:17:32Zhow to generate two random binary images with remove overlapping ?hi,
I am looking to creat two random binary images with remove overlapping. the second image should be random and not contact or overlape with first one.I have did this code:
clc; clear all;
A=[0 0 0 0 ;...
0 0 0 0 ;...
0 0 0 0 ;...
0 0 0 0 ;...
0 0 0 0];
N =2;
for k= 1:N
if k>1
(A(y0:y1,x0:x1)+1)==[];
if A>=0
X(k,:) = randi([1,min(size(A))],1,2);
Y(k,:) = randi([1,min(size(A))],1,2);
x0= min(X(k,:));
x1= max(X(k,:));
y0= min(Y(k,:));
y1= max(Y(k,:));
A(y0:y1,x0:x1)=1;
xyStart(k,:) = [y0,x0];
xyEnd(k,:) = [y1,x1];
end
else
X(k,:) = randi([1,min(size(A))],1,2);
Y(k,:) = randi([1,min(size(A))],1,2);
x0= min(X(k,:));
x1= max(X(k,:));
y0= min(Y(k,:));
y1= max(Y(k,:));
A(y0:y1,x0:x1)=1;
xyStart(k,:) = [y0,x0];
xyEnd(k,:) = [y1,x1];
end
end
this code work with first one but does not work with the seconed image, could you please help me?
one example of expect answer:(Note it are random)
A=[1 1 0 0 ;...
1 1 0 0 ;...
0 0 0 0 ;...
0 1 1 1 ;...
0 1 1 1];
Mohammed Alammarhttps://nl.mathworks.com/matlabcentral/profile/authors/13292041-mohammed-alammartag:nl.mathworks.com,2005:Question/4951252019-12-05T23:28:16Z2019-12-06T00:16:13Zposition, velocity, acceleration function [x] = my_lost_package(t)
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
syms t
g = 9.8;
t = input("please enter a time") %input for time
x = .5*g*t.^2 % distance travel i meters.
fplot(my_lost_package,'-r')
hold on
velocity = diff(x)
plot(velocity, '--r')
hold on
acceleration = diff(velocity)
plot(acceleration)
axis([0,60,0,1800])
xlabel('time (s)')
ylabel('distance(m)')
title('falling object')
blake brandthttps://nl.mathworks.com/matlabcentral/profile/authors/16043491-blake-brandttag:nl.mathworks.com,2005:Question/4951262019-12-05T23:53:27Z2019-12-06T00:14:18ZMake comet move with respect to a functionI've got a function x,y (coordinates) and another t,v, (velocity with respect to time) I want to make that the function comet moves according to the x,y function slower or faster with respect to the function of velocity with respect of time, how can I make this?Alejandro Castrohttps://nl.mathworks.com/matlabcentral/profile/authors/12549721-alejandro-castrotag:nl.mathworks.com,2005:Question/4950812019-12-05T18:21:10Z2019-12-06T00:10:04ZHow do I fix an error when regionprops finds no blob?In my binary image, there is no blob/ 0 pixel /white pixel. It shows me an error.
Here is my code:
Obj = regionprops(binaryImage, gambarAsliParkir1, 'Area' , 'BoundingBox');
[~, numbersOBJECT] = bwlabel(binaryImage);
clear P1;
for i=1:numbersOBJECT
area= Obj(i).Area;
P1(i)=area; %#ok<AGROW>
endAaron Abelhttps://nl.mathworks.com/matlabcentral/profile/authors/11506487-aaron-abeltag:nl.mathworks.com,2005:Question/1021742013-04-25T15:56:00Z2019-12-06T00:06:05ZHow to change the axis limits and remove/alter the ticks and labels for a COMPASS/POLAR plot?I would like to change the axes properties of a compass plot within the code without using the manual plotting edit tool.
For instance, I would like to:
1) Set the magnitude of the axis to a certain maximum number no matter what the data is that I am plotting.
2) Change the rotational axis labels.
MathWorks Support Teamhttps://nl.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:nl.mathworks.com,2005:Question/4951242019-12-05T23:16:50Z2019-12-05T23:57:22Zsave a probability matrix (range [0, 1]) as grayscale image with range [0,1]I need to save an mxn probability matrix (values in range [0, 1], single) as an image (png, tif, etc.). I want the values to stay in the [0 1] range and not scaled to 0-255 (uint8) or other like what imwrite does. Can it be done in Matlab? Thank you.Mina Gheiratmandhttps://nl.mathworks.com/matlabcentral/profile/authors/16392009-mina-gheiratmandtag:nl.mathworks.com,2005:Question/4950762019-12-05T17:57:19Z2019-12-05T23:55:03Zindex exceeds array bounds%Program for simple
this is my code but when i run it this comes up:
Enter value of m: -5
Index exceeds array bounds.
Error in u1828202 (line 34)
disp('Redo the value for m')
mass spring damper system
m=20; %Default mass in kg
k1=100; %default spring constant in N/m
k2=50; %default spring constant in N/m
b1=2; %Damping coefficient in N sm^-1
b2=2; %Damping coefficient in N sm^-1
ttotal=50; %total integration time in s
d=0.1; %Gap in m
dt=0.01; %Integration step in s
e=-1.0;%Initial displacement in s
t=[0:dt:ttotal];
n=length(t);
x=zeros(n,1);
v=zeros(n,1);
a=zeros(n,1);
x(1)=e;
v(1)=0;
a(1)=-(k1*x(1)+b1*v(1))/m;
for i=2:n
v(i)=a(i-1)*dt+v(i-1);
x(i)=v(i)*dt+x(i-1);
if x(i)<d
a(i)=-k1*x(i)+b1*v(i)/m;
else
end
end
%prompt for user-defined parameters
m=input('Enter value of m: ');
if (m<=0)
disp('Redo the value for m')
end
k1=input('Enter value of k1: ');
k2=input('Enter value of k2: ');
b1=input('Enter value of b1: ');
b2=input('Enter value of b2: ');
ttotal=input('Enter value for ttotal: ');
d=input('Enter value for gap: ');
dt=input('Enter value for integration step: ');
x=input('Enter value for initial displacement: ');
disp=("Acceleration is now equal to: ")
disp(a(i));
disp=('Velocity is now equal to: ');disp(v(i));
Abdul Burhanhttps://nl.mathworks.com/matlabcentral/profile/authors/17032496-abdul-burhantag:nl.mathworks.com,2005:Question/4936442019-11-28T08:29:57Z2019-12-05T23:36:58ZSample time of Host Scopes in Simulink Real-timeHi
I am using Host Scopes to capture signal data of my model running on a Simulink Real-time target. My base model has a sample time of 24000Hz, but almost all blocks inside the model are running on 8000 Hz. The timing legend shows that there are in fact no blocks/signals running at 24kHz:
I have configured the Host Scope to log a signal inside a part that runs on 8000 Hz, with Decimation set to 1. However, the signal data is still sampled at 24000 Hz.
I am not surprised that Decimation = 1 means a sampling at 24000 Hz, but I am surprised that the signal data is different at each sample, while the signal is only going at 8000 Hz.
Shouldn't I need to see the same signal value very three samples? How can it sample at 24kHz in a 8kHz section?
With kind regards,
JonasJonashttps://nl.mathworks.com/matlabcentral/profile/authors/10802703-jonastag:nl.mathworks.com,2005:Question/4951132019-12-05T21:44:09Z2019-12-05T23:33:19Zediting a string using GUI editable text/popup within guideI have a string, where I use strrep to replace a variable witha user input:
string = ('Today, I ate some (x)')
user_input = input('Enter your food: ', 's');
newstring = strrep('string', '(x)', user_input);
I want to use an editable textbox to get user_input. How would I do that?
My full script will have 3 editable textboxes, and 2 popups.
the popups will be changing a directory path, like I do here with sprintf:
user_input_food = input('enter food: ');
user_input_amount = input('enter amount: ');
root = 'C:\Users\Administrator';
% full path should look like C:\Users\Administrator\food\amount\food_amount.txt
filepath = fullfile(root, sprintf('food%s', user_input_food,), user_input_amount, sprintf('food%s_amount%s.txt', user_input_food, user_input_amount);
how do I get a popup menu to populate the user_input_experiment/user_input_squad variables?avram alterhttps://nl.mathworks.com/matlabcentral/profile/authors/13236963-avram-altertag:nl.mathworks.com,2005:Question/4951002019-12-05T20:15:14Z2019-12-05T23:29:14Zhow to evaluate definite integralCould anyone please help to find wat is wrrong here in the f ?
Thanks
ho= 2;
ep = 0.0:0.01:0.1;
% ep = 0.02;
L = 3;
q = 14.4;
mu = 10^8;
X = 2 * pi * x /L;
f = @(X) 1./(ho(1 + (ep .* sin(X))))^3;
P = integral(f,0,L);
% Fvpaint = vpaintegral(f,X,[0 L])
pr = - 3/2 *mu *q * P
plot ( ep, pr)Mat1https://nl.mathworks.com/matlabcentral/profile/authors/6881386-mat1tag:nl.mathworks.com,2005:Question/4951212019-12-05T23:03:14Z2019-12-05T23:21:34Zhow i can separate the different mix up voices in matlab i have no code
i have only the audio in which five or six people taking to each other and i want to separate the voice and listen it one by one
Muhammad murtazahttps://nl.mathworks.com/matlabcentral/profile/authors/13931295-muhammad-murtazatag:nl.mathworks.com,2005:Question/4951232019-12-05T23:05:32Z2019-12-05T23:05:32ZI solved the differential equation by eigenvalues/eigenvectors, how would I solve for the constants from my initial conditions?syms lambda
A = [-8/3 0 0; 8/3 -8/2 0; 0 8/2 -8/24];
Id3 = sym([1,0,0;0,1,0;0,0,1])
B = lambda*Id3-A
evs = solve(p)
null(evs(1)*Id3-A)
[evctrs,d] = eig(A)
x0 = [3; 7; 6];
lambda_1 = d(1,1);
lambda_2 = d(2,2);
lambda_3 = d(3,3);
vec_1 = evctrs(:,1);
vec_2 = evctrs(:,2);
vec_3 = evctrs(:,3);
syms C1 C2 C3 t
X = C1*vec_1*exp(-lambda_1*t)+C2*vec_2*exp(-lambda_2*t)+C3*vec_3*exp(-lambda_3*t)
% I have initial conditions x1(0)=3, x2(0)=7, and x3(0)=6, but I am not sure how I would equate them to solve for the constants in my equation.Sophia Hornerhttps://nl.mathworks.com/matlabcentral/profile/authors/13320609-sophia-hornertag:nl.mathworks.com,2005:Question/4951222019-12-05T23:05:22Z2019-12-05T23:05:22ZSimulink Project Opens Multiple Copies when Simulink Design Verifier is RunI created a simulink project with multiple models, main high level model, plant model and control model. It works fine. I added simulink design verifier to my project to verify some prepreties in the control model (SLDV is run on the control model only). I run simulink design verifier in property proving mode not in test generation. It generated the report. Then, whenever I open the project it opens many copies of the main model. I cleard the simulink cache folder and SLDV output folder but the problem still there. What am I missing here? I assume that SLDV creates multiple test scenarios to falsify the requirements but why they are called everytime I open the project even without calling the test harness?
ahmed Ghareebhttps://nl.mathworks.com/matlabcentral/profile/authors/3493842-ahmed-ghareebtag:nl.mathworks.com,2005:Question/4951012019-12-05T20:18:23Z2019-12-05T22:58:10ZFzero is not working isn=1.5;
h=5e-6;
x=2*pi*3e14;
%
fzero(@(y)(tan(sqrt(x.^2.*n^2/const('c')^2-y.^2)*h/2)-sqrt(y.^2-x.^2/const('c')^2./sqrt(x.^2*n^2/const('c')^2-y.^2))))
Fzero is unable to find the rootShlok Vaibhav Singhhttps://nl.mathworks.com/matlabcentral/profile/authors/15417835-shlok-vaibhav-singhtag:nl.mathworks.com,2005:Question/4950992019-12-05T20:14:09Z2019-12-05T22:52:59ZHow to plot dispersion curve for optical waveguide
I want to produce a dispersion curve for optical waveguide like one in above picture:
But fsolve is not workingShlok Vaibhav Singhhttps://nl.mathworks.com/matlabcentral/profile/authors/15417835-shlok-vaibhav-singhtag:nl.mathworks.com,2005:Question/4951102019-12-05T21:00:53Z2019-12-05T22:50:05ZHow to reduce For loop execution time?I have following Matlab code to calculate summation of exponential summation term:
This code takes approx. 600 seconds to give final output s. Is there any way to reduce this computation time?
sum1 = 0;
s = 0;
for i=1:1000000000
for j=1:3
sum1 = sum1+(i*proc(j))^2;
end
s = s+exp(-sum1);
endAjinkya Bankarhttps://nl.mathworks.com/matlabcentral/profile/authors/15571509-ajinkya-bankartag:nl.mathworks.com,2005:Question/4849552019-10-12T19:52:12Z2019-12-05T22:48:59ZMatlab 2019b not working mac OS Catalina - Start desktop error Hi everyone,
Has anyone managed to use 2019b version with the new Catalina OS Mac update ?
Despite, the compatibility stated at https://www.mathworks.com/support/requirements/matlab-system-requirements.html.
I get an error message "error starting desktop" pointing towards what seems to be a java issue.
Matlab was working perfectly before the update to Catalina.
Thank you very much.
Justine Guillochonhttps://nl.mathworks.com/matlabcentral/profile/authors/15999988-justine-guillochontag:nl.mathworks.com,2005:Question/4951192019-12-05T22:40:16Z2019-12-05T22:40:16ZUse of backslash while calculating the product of inverse of a matrix and another matrixI am trying to implement successive overrelaxation method. I am getting different answers when I distributed the inverse between two matrices
First way:
xt = (D+omg*L)\((D*(1-omg)-omg*U)*xn+omg*B);
Second way:
xt = (D+omg*L)\((D*(1-omg)-omg*U)*xn)+omg*(D+omg*L)\B);
where D, L, and U are matrices of same size, xn is a vector and omg is a scalar value. But when I use "inv" function instead of backslash, I am getting the same answer in both the cases i.e,
xt = inv(D+omg*L)*((D*(1-omg)-omg*U)*xn+omg*B);
xt = inv(D+omg*L)*((D*(1-omg)-omg*U)*xn)+omg*inv(D+omg*L)*B);Yaswanth Saihttps://nl.mathworks.com/matlabcentral/profile/authors/8803177-yaswanth-saitag:nl.mathworks.com,2005:Question/4951182019-12-05T22:34:06Z2019-12-05T22:34:06ZHow to export an RL policy from MATLAB to python?I am trying to export the policy from the Basic Gridworld example to Python using exportONNXnetwork. It doesnt seem to be working for me. Anybody here who knows how to pull this off ?
P.S: I am new to this, so please bear with my silly doubts.Shikhar Sharmahttps://nl.mathworks.com/matlabcentral/profile/authors/16051027-shikhar-sharmatag:nl.mathworks.com,2005:Question/4951172019-12-05T22:23:57Z2019-12-05T22:32:17ZImage labeler Train cascade error!Hi,
I have a set of labeled images using the image labeler app. I have exported using the builtin function to gTruth file.
I have the following code:
load('gTruth.mat');
positiveInstances = gTruth(:,2:1);
imDir = fullfile('positveImgDir');
addpath(imDir);
negativeFolder = fullfile('NegativeImgDir');
negativeImages = imageDatastore(negativeFolder);
trainCascadeObjectDetector('bluesDetector.xml',positiveInstances, ...
negativeFolder,'FalseAlarmRate',0.1,'NumCascadeStages',5);
However, I get the following error.
Error using trainCascadeObjectDetector>parseInputs (line 317)
The value of 'positiveInstances' is invalid. Expected input number
2, positiveInstances, to be one of these types:
struct, char, table
Instead its type was groundTruth.
Error in trainCascadeObjectDetector (line 168)
parser = parseInputs(varargin{:});
Error in matcherFile (line 9)
trainCascadeObjectDetector('bluesDetector.xml',positiveInstances,
...
when I change to:
positiveInstances = gTruth(:,1:2);
I get this error:
Index in position 2 exceeds array bounds (must not exceed 1).
Error in templatematcher (line 2)
positiveInstances = gTruth(:,1:2);
I have no idea why it is causing this error. Additionally, the ground truth file labeled data table does not contain the objectboundingboxes only the pixel label data. Any help will be appreciated.
AAAAhttps://nl.mathworks.com/matlabcentral/profile/authors/16204118-aaaatag:nl.mathworks.com,2005:Question/4817082019-09-23T14:27:43Z2019-12-05T22:31:52ZTopology Optimization - What does 2 and 1 mean in F(2,1)? (line 79 in the code)This is a standard code for the topology optimization of a MBB beam as in the figure. The force has to be defined at the upper left corner. The design domain is descretized into finite elements, say 9 elements in the x-direction and 3 elements in the y-direction. Both node numbers and element numbers are numbered column wise from left to right. I am under the impression that the force is applied on the node. In that case the node number 1. But what does F(2,1) mean?
%%%% A 99 LINE TOPOLOGY OPTIMIZATION CODE BY OLE SIGMUND, JANUARY 2000 %%% %%%% CODE MODIFIED FOR INCREASED SPEED, September 2002, BY OLE SIGMUND %%%
function top_mbb(nelx,nely,volfrac,penal,rmin);
% INITIALIZE
x(1:nely,1:nelx) = volfrac;
loop = 0;
change = 1.;
% START ITERATION
while change > 0.01
loop = loop + 1;
xold = x;
% FE-ANALYSIS
[U]=FE(nelx,nely,x,penal);
% OBJECTIVE FUNCTION AND SENSITIVITY ANALYSIS
[KE] = lk;
c = 0.;
for ely = 1:nely
for elx = 1:nelx
n1 = (nely+1)*(elx-1)+ely;
n2 = (nely+1)* elx +ely;
Ue = U([2*n1-1;2*n1; 2*n2-1;2*n2; 2*n2+1;2*n2+2; 2*n1+1;2*n1+2],1);
c = c + x(ely,elx)^penal*Ue'*KE*Ue;
dc(ely,elx) = -penal*x(ely,elx)^(penal-1)*Ue'*KE*Ue;
end
end
% FILTERING OF SENSITIVITIES
[dc] = check(nelx,nely,rmin,x,dc);
% DESIGN UPDATE BY THE OPTIMALITY CRITERIA METHOD
[x] = OC(nelx,nely,x,volfrac,dc);
% PRINT RESULTS
change = max(max(abs(x-xold)));
disp([' It.: ' sprintf('%4i',loop) ' Obj.: ' sprintf('%10.4f',c) ...
' Vol.: ' sprintf('%6.3f',sum(sum(x))/(nelx*nely)) ...
' ch.: ' sprintf('%6.3f',change )])
% PLOT DENSITIES
colormap(gray); imagesc(-x); axis equal; axis tight; axis off;pause(1e-6);
end
%%%%%%%%%% OPTIMALITY CRITERIA UPDATE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [xnew]=OC(nelx,nely,x,volfrac,dc)
l1 = 0; l2 = 100000; move = 0.2;
while (l2-l1 > 1e-4)
lmid = 0.5*(l2+l1);
xnew = max(0.001,max(x-move,min(1.,min(x+move,x.*sqrt(-dc./lmid)))));
if sum(sum(xnew)) - volfrac*nelx*nely > 0;
l1 = lmid;
else
l2 = lmid;
end
end
%%%%%%%%%% MESH-INDEPENDENCY FILTER %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [dcn]=check(nelx,nely,rmin,x,dc)
dcn=zeros(nely,nelx);
for i = 1:nelx
for j = 1:nely
sum=0.0;
for k = max(i-floor(rmin),1):min(i+floor(rmin),nelx)
for l = max(j-floor(rmin),1):min(j+floor(rmin),nely)
fac = rmin-sqrt((i-k)^2+(j-l)^2);
sum = sum+max(0,fac);
dcn(j,i) = dcn(j,i) + max(0,fac)*x(l,k)*dc(l,k);
end
end
dcn(j,i) = dcn(j,i)/(x(j,i)*sum);
end
end
%%%%%%%%%% FE-ANALYSIS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [U]=FE(nelx,nely,x,penal)
[KE] = lk;
K = sparse(2*(nelx+1)*(nely+1), 2*(nelx+1)*(nely+1));
F = sparse(2*(nely+1)*(nelx+1),1); U = zeros(2*(nely+1)*(nelx+1),1);
for elx = 1:nelx
for ely = 1:nely
n1 = (nely+1)*(elx-1)+ely;
n2 = (nely+1)* elx +ely;
edof = [2*n1-1; 2*n1; 2*n2-1; 2*n2; 2*n2+1; 2*n2+2; 2*n1+1; 2*n1+2];
K(edof,edof) = K(edof,edof) + x(ely,elx)^penal*KE;
end
end
% DEFINE LOADS AND SUPPORTS (HALF MBB-BEAM)
F(2,1) = -1;
fixeddofs = union([1:2:2*(nely+1)],[2*(nelx+1)*(nely+1)]);
alldofs = [1:2*(nely+1)*(nelx+1)];
freedofs = setdiff(alldofs,fixeddofs);
% SOLVING
U(freedofs,:) = K(freedofs,freedofs) \ F(freedofs,:);
U(fixeddofs,:)= 0;
%%%%%%%%%% ELEMENT STIFFNESS MATRIX %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [KE]=lk
E = 210.;
nu = 0.3;
k=[ 1/2-nu/6 1/8+nu/8 -1/4-nu/12 -1/8+3*nu/8 ...
-1/4+nu/12 -1/8-nu/8 nu/6 1/8-3*nu/8];
KE = E/(1-nu^2)*[ k(1) k(2) k(3) k(4) k(5) k(6) k(7) k(8)
k(2) k(1) k(8) k(7) k(6) k(5) k(4) k(3)
k(3) k(8) k(1) k(6) k(7) k(4) k(5) k(2)
k(4) k(7) k(6) k(1) k(8) k(3) k(2) k(5)
k(5) k(6) k(7) k(8) k(1) k(2) k(3) k(4)
k(6) k(5) k(4) k(3) k(2) k(1) k(8) k(7)
k(7) k(4) k(5) k(2) k(3) k(8) k(1) k(6)
k(8) k(3) k(2) k(5) k(4) k(7) k(6) k(1)];
Any help would be appreciated.
Thank you!
Sankalp Patilhttps://nl.mathworks.com/matlabcentral/profile/authors/11331148-sankalp-patiltag:nl.mathworks.com,2005:Question/4950962019-12-05T19:56:37Z2019-12-05T22:26:45ZNetcdf NC4 unable to display variables and merge 4000 nc files I have two task. The file is 84mb so could nt upload here
Can't open or display the Netcdf file variables. ncdisp(filename) has shown all the variables in the dataset,
To merge all 4000 daily .nc4 files and subset for a region
/qa_statistics/
Variables:
data_quality_flag
Size: 3600x1800
Dimensions: /longitude,/latitude
Datatype: int8
Attributes:
_FillValue = 2
comment = 'main data quality flag. 0 (good, number of samples > 0.1)1 (good, number of samples < 0.1) 2 (bad / not computed)'
long_name = 'main data quality flag'
falg_values = [0 1 2]
flag_meanings = 'good_number_of_samples_greater_than_0.1 good_number_of_samples_less_than_0.1 bad_or_not_computed'
valid_min = 0
valid_max = 2
coordinates = 'longitude latitude'
_Storage = 'contiguous'
/support_data/
Variables:
albedo
Size: 3600x1800
Dimensions: /longitude,/latitude
Datatype: single
Attributes:
_FillValue = -1.000000015047466e+30
comment = 'surface albedo'
long_name = 'surface albedo'
units = '1'
valid_min = 0
valid_max = 1
coordinates = 'longitude latitude'
_Storage = 'contiguous'
terrain_height
Size: 3600x1800
Dimensions: /longitude,/latitude
Datatype: int16
Attributes:
_FillValue = -30000
comment = 'terrain height'
long_name = 'terrain height'
units = 'm'
valid_min = -1000
valid_max = 10000
coordinates = 'longitude latitude'
_Storage = 'contiguous'
I get following errors:
"Error using internal.matlab.imagesci.nc/getGroupAndVarid (line 2096)
Could not find variable or group 'sample_weight' in file.
Error in internal.matlab.imagesci.nc/read (line 593)
[gid, varid] = getGroupAndVarid(this, location);
Error in ncread (line 66)
vardata = ncObj.read(varName, varargin{:});"
Finally, how to read .he5 (hdf file)Dim Dehttps://nl.mathworks.com/matlabcentral/profile/authors/17033244-dim-detag:nl.mathworks.com,2005:Question/4951152019-12-05T21:57:37Z2019-12-05T22:13:44ZHow can set colormap for below matirx?Hello Friends.
The below code calculates an matrix eta2. and then display some shapes that each of them is on specified positions. For displaying it, I used imagesc(eta2).
Also, etas is a matrix that its value varies between 0 and 1 randomly. Indeed, each grain has own values between grid points i and j.
Now I am looking for determining a custom color for each of grains. How can do it.
Thanks.
%code
Nx=128;%grid
Ny=Nx;
eta2 = zeros(Nx,Ny);
etas = rand(Nx*Ny,25));
for igrain=1:25
ncount=0;%counter
for i=1:Nx
for j=1:Nx
ii =(i-1)*Nx+j;
eta2(i,j) =eta2(i,j)+etas(ii,igrain)^2; %calculating the eta2.
if(etas(ii,igrain) >= 0.5)
ncount=ncount+1;
end
%
ncount=ncount/(Nx*Ny);
end
end%Nx
end%igrain
%%Display
figure
imagesc(eta2);Amir Torabihttps://nl.mathworks.com/matlabcentral/profile/authors/15483036-amir-torabitag:nl.mathworks.com,2005:Question/4948612019-12-04T17:37:18Z2019-12-05T22:10:22ZThingspeak - Public Channel - Viewer CounterHello everyone,
I was wondering if it was possible to have a 'website visitor counter' that tracks the number of people that visits my public channel.
Not critical but it would be really nice to see.Frank Siepkerhttps://nl.mathworks.com/matlabcentral/profile/authors/16741638-frank-siepkertag:nl.mathworks.com,2005:Question/4951112019-12-05T21:25:51Z2019-12-05T22:06:59ZMinimize Function with multiple inputs I am working on a project where I must model part of a jet engine. We have a lot of constants and 4 variables with constraints. There are then about 30 equations or so that connect together, where we look at how properties change going through the engine. We end up with a fuel flow rate, which I need to minimize by variying the 4 variables. How would I optimize this using matlab? Looking at optimization methods, it seems they have single function that variables are plugged into. I can't create a single equation to represent all these relationships. Austin Connellhttps://nl.mathworks.com/matlabcentral/profile/authors/10830891-austin-connelltag:nl.mathworks.com,2005:Question/4951142019-12-05T21:53:15Z2019-12-05T21:57:46ZModal Analysis of a beamI am trying to do the modal analysis of a beam. I did the modal analysis in Ansys to check the results, for the same frequency range, the same material properties and the same boundary conditions Ansys finds only 6 modes, while matlab finds more than 750.
Matlab imports geometry strangely, I don't know if that has anything to do with it
Enrique Ortega Pinzónhttps://nl.mathworks.com/matlabcentral/profile/authors/15873211-enrique-ortega-pinzontag:nl.mathworks.com,2005:Question/4372372018-12-26T08:30:09Z2019-12-05T21:47:11ZWhy can't I set populationsize of GA to vector?Why can't I set PopulationSize of GA to a vector?
Although the document says
>If you set Population size to a vector, the genetic algorithm creates multiple subpopulations, the >number of which is the length of the vector. The size of each subpopulation is the corresponding entry >of the vector.
https://jp.mathworks.com/help/gads/genetic-algorithm-options.html
the code below shows error in PopulationSize.
vector_populationSize = [600 600 600 600];
options = optimoptions('ga', 'PopulationSize',vector_populationSize,...
'Generations',100,...
'PopulationType', 'bitstring',...
'SelectionFcn',{@selectionstochunif},...
'MutationFcn',{@mutationuniform, 0.5},...
'CrossoverFcn', {@crossoversinglepoint,0.5},...
'EliteCount',150,...
'MigrationFraction', 0.08,...
'MigrationInterval', 10,...
'MaxStallGenerations', 10000,...
'UseParallel', true,...
'Display', 'iter');Lu Chenhttps://nl.mathworks.com/matlabcentral/profile/authors/14379999-lu-chentag:nl.mathworks.com,2005:Question/4950982019-12-05T20:13:05Z2019-12-05T21:42:30ZWhat plans are there for native support on ARM v8 64 bit CPUS 64 bit ARM CPUS are now viable options for high performance scientific computing, and Red Hat now supports RHEL on ARM as a equal platform to x86. When will matlab be avaliable nativley for ARM systems?
Alastair Neilhttps://nl.mathworks.com/matlabcentral/profile/authors/1417286-alastair-neiltag:nl.mathworks.com,2005:Question/4950912019-12-05T19:15:30Z2019-12-05T21:40:28ZHow can I modify the default options (like RelTol' and 'AbsTol') of the pde solver when using the PDE toolbox?When working in 1D, I can modify the default options of the solver by using odeset and then calling the 'options' with pdepe, for example:
options = odeset('RelTol',1e-13,'AbsTol',1e-13);
sol = pdepe(m,'pde','ic','bc',x,t,options)
Now I am working in a 2D probelm and I am using the PDE toolbox. How can I especify options when working with the PDE toolbox? I use the command line function solvepde and I I would like to set more strict Relative error tolerance and Absolute error tolerance.
Apparently, the function solvepde calls ode15s which allows the especification of 'options'.
Thank you.Mario Di Salvohttps://nl.mathworks.com/matlabcentral/profile/authors/16109725-mario-di-salvo