https://in.mathworks.com/matlabcentral/answers/questionsMATLAB Answers — New Questions2019-12-07T08:38:18Ztag:in.mathworks.com,2005:Question/4953642019-12-07T07:02:29Z2019-12-07T08:38:18ZHow to create a circle within a matrix Need to figure out how to create a circle of a specificed size and position, within a premade matrix of zero's. Currently I have the code for the Matrix set and I am able to control the boundaries of the maxtrix. but I would like to be able to place a circle matrix of desired radius and location within the maxtrix of zero's Ive specified
cx1 = .01; %x position of circle
cy1 = .05; %y position of circle
cr1 = .02; %radius of circle
th = 0:pi/100:2*pi;
xunit = cr1 * cos(th) + cx1
yunit = cr1 * sin(th) + cy1
plot (xunit,yunit)
viscircles([centerX, centerY], radius);
x=-.10:.02:.10;
[X,Y]=meshgrid(x); % xy space
v1=zeros(size(X)); % previous v
v1(xunit,yunit)=10 % top boundary CONTROLS COLOR BAR
v1(end,:)=10 % bottom boundary
v1(:,1)=10 % left boundary
v1(:,end)=10 % right boundaryEdward Villanuevahttps://in.mathworks.com/matlabcentral/profile/authors/10910607-edward-villanuevatag:in.mathworks.com,2005:Question/4953712019-12-07T08:26:56Z2019-12-07T08:26:56Zconvert the table which has both number and string as csv or arff (WEKA) ?I'm unable to convert this into csv or arff file. CalebJoneshttps://in.mathworks.com/matlabcentral/profile/authors/6730761-calebjonestag:in.mathworks.com,2005:Question/4953702019-12-07T08:20:49Z2019-12-07T08:20:49ZPower spectrum of audio signalIf i have an audio file, an .m4a file for example, how do i plot the power spectrum of such a signal (without redundant data) with the frequency axis in Hz given that the audio signal is sampled at 40000 Hz?Quant.Phys42https://in.mathworks.com/matlabcentral/profile/authors/12321949-quant-phys42tag:in.mathworks.com,2005:Question/4953692019-12-07T07:54:11Z2019-12-07T07:57:16ZI want to make a chart which shows some values of end-effector in real-timeHi, I'm currently a student of engineering college, and i am doing robot arm simulation with mechanics explorer and Simulink.
I want to make a chart which shows the position, angle, error of the end-effector in real-time as it moves.
And then I want to insert this realtime chart on the right side with robot:
Please, Help me !!Hyungi Kimhttps://in.mathworks.com/matlabcentral/profile/authors/13426808-hyungi-kimtag:in.mathworks.com,2005:Question/4953652019-12-07T07:09:16Z2019-12-07T07:53:00Zhow to get the last row of a matrix in simulinkhow to get the last row of a 2-D matrix in simulink without knowing the matrix's size?(matrix size is variable)Yang Shenhttps://in.mathworks.com/matlabcentral/profile/authors/9758223-yang-shentag:in.mathworks.com,2005:Question/4953532019-12-07T05:46:25Z2019-12-07T07:52:16ZHOW TO DO FEATURE EXTRACTION OF FRESH AND ROTTEN FRUITS.Hi, i need to do my assignment which is to do feature extraction of fresh and rotten fruits. I have 6 folders of fresh and rotten fruits which are Fresh Apples, Fresh Oranges, Fresh Bananas, and Rotten Apples, Rotten Oranges, Rotten Bananas. How to do the extraction to detect the fresh and rotten fruits? Thank you in advance.Aina Kiflihttps://in.mathworks.com/matlabcentral/profile/authors/16978385-aina-kiflitag:in.mathworks.com,2005:Question/4953492019-12-07T03:58:20Z2019-12-07T07:43:32ZWarning creating vertical line using xline I ran into a warning when using the xline function. I went all the way back to running the simple code in the MATLAB help on xline and still get the same warning. Here's the code from help:
x = linspace(0,6,100);
y = exp(x);
plot(x,y)
xline(4.5,'-',{'Acceptable','Limit'});
The following warning appears:
Warning: Error updating ConstantLine.
Too many input arguments.
Warning: Error creating or updating CompositeMarker
Error in value of property Anchor
Array is null
Warning: An error occurred while drawing the scene: Cookie 0 does not refer to a node in the scene tree
The plot appears as the one in the MATLAB help, but the label on the vertical line is not drawn:
If I try to select the vertical line with the "Edit Plot" arrow, the warning is repeated in the command window and there is no visible indication I have selected the line. However, if I have the property inspector open, it shows I have the vertical line selected. I can also see the appropriate label in the property inspector for the vertical line. If I delete the label text in the property inspector, the selection indicators appear at each end of the line and the warning is no longer repeated in the command window. If I type a new label in the property inspector, the label appears at the plot origin and a warning again appears in the command window.
Warning: Error updating ConstantLine.
Too many input arguments.
Warning: Error creating or updating CompositeMarker
Error in value of property Anchor
Array is null
Obviously, the help example should not be causing this issue. Maybe my settings or preferences are causing the problem? I've closed and reopened MATLAB a few times thinking something could have gotten in a weird state, but that did not change anything. Any ideas about what might be happening?
Edit: I tried the same xline command without the label and it works without the warning. If I add a single line label, for example,
xline(4.5,'-','Limit');
it produces the same warning and behavior as the multi-line label in the example.
When trying to debug the error, I get into the internal MATLAB .m file xyzline.m. The warning appears after executing Line 85:
hcl.Parent = parentAxes;
Edit 2: The warning that is thrown does not come from xyzline.m. It is thrown by defaulterrorcallback.m. The id is "MATLAB:handle_graphics:Canvas:RenderingException" and the msg is "An error occurred while drawing the scene: Cookie 0 does not refer to a node in the scene tree." I wonder if there is something wrong with my graphics rendering settings.Matthttps://in.mathworks.com/matlabcentral/profile/authors/1460942-matttag:in.mathworks.com,2005:Question/337012012-03-28T07:23:20Z2019-12-07T07:36:31Zsimulation of fault location on transmission line by using matlab I am currently doing a project about fault location detection on transmission line by using travelling wave method. I wished to use simulink to simulate the fault detection on multi circuit lines. Can anyone kindly guide me on this? Jirohttps://in.mathworks.com/matlabcentral/profile/authors/1984950-jirotag:in.mathworks.com,2005:Question/4949672019-12-05T08:20:36Z2019-12-07T07:34:09Zsave spacific entity from matrixa1=input('give vale if th_1:');
a2=input('give vale if th_2:');
a3=input('give vale if th_3:');
th_1= (a1*pi/180)
th_2= (a2*pi/180);
th_3= (a3*pi/180);
L(1) = Link([ 0 0 20 0 0], 'standard');
L(2) = Link([ 0 0 20 0 0], 'standard');
L(3) = Link([ 0 0 20 0 0], 'standard');
Rob=SerialLink(L);
Rob.name='user nput rob';
Rob.plot([th_1 th_2 th_3]);
T=Rob.fkine([th_1 th_2 th_3])
i have tis code when i run this code it give T 4*4 matrix but when i try to save specifix entities from
T matrix it will give error"Index in position 1 exceeds array bounds (must not exceed 1)"
for saving entity i use this command
h=T(1,4); kindly helpHafiz Muhammad Saqib Ashfaqhttps://in.mathworks.com/matlabcentral/profile/authors/16964884-hafiz-muhammad-saqib-ashfaqtag:in.mathworks.com,2005:Question/4952992019-12-06T20:55:20Z2019-12-07T07:29:10ZMap a 2D matrix into 3D using loop for allotment along the 3rd dimensionI am not able to map a 2D matrix into a 3D, in which I want the particular columns of original 2D matrix to be selected and separated by using 3rd dimension (or in other words breaking a continous data into trials based on columns' selection). I used to get it before, but somehow, I am facing trouble while doing this- it throws an error of "Subscripted dimension error mismatch". But, if I do allotment along the 3rd dimension, size mismatch in other 2 dimensions should not create a problem, this is what I think.
I am now doubtful after getting the dimension mismatch error for it in matlab.
My code is somewhat like this:
% data is 2D matrix of size 7*1298779
for i=1:20
data_trialwise(:,:,i)=data(:,begin(i):end(i)); % begin and end both have 20 elements with values less than the number of columns in data
end
Ritzhttps://in.mathworks.com/matlabcentral/profile/authors/12539293-ritztag:in.mathworks.com,2005:Question/3931202018-04-06T15:26:14Z2019-12-07T07:08:57ZTransfer Learning with GoogLeNet Error when Freezing WeightsHello,
Recently I have been exploring the machine learning and neural network capabilities of Matlab and I have been trying to use transfer learning on the GoogLeNet pretrained network to see how it performs on some text recognition datasets.
I have been following the syntax closely in the documentation <https://www.mathworks.com/help/nnet/examples/transfer-learning-using-googlenet.html here> but I'm encountering some errors when I try to freeze the initial layers. The syntax in the example is as follows:
layers = lgraph.Layers;
connections = lgraph.Connections;
layers(1:110) = freezeWeights(layers(1:110));
lgraph = createLgraphUsingConnections(layers,connections);
For some reason when trying to set the layers and connections variables as is shown above, I get the error message "The expression to the left of the equals sign is not a valid target for an assignment". This happens both when I try to assign the 'layers' and 'connections' variables. Strangely enough, I can set both of these variables if I first type 'lgraph.Layers' or 'lgraph.Connections' into the workspace and then following those workspace, allowing the '.Layers' or '.Connections' properties be stored in the default temporary variable 'ans' and then setting the desired variables with "layers = ans" or "connections = ans".
The second problem I am encountering is with the 'freezeWeights()' command. When I try to run that I get the error message, "Undefined function or variable 'freezeWeights'" which is strange considering I have downloaded the googleNet support package. Is there another support package that has the freezeWeights command? I can't seem to find anything on that command.
Thank you for any assistance.Andrew Chenhttps://in.mathworks.com/matlabcentral/profile/authors/8216835-andrew-chentag:in.mathworks.com,2005:Question/4953442019-12-07T03:17:23Z2019-12-07T06:59:55ZFunction: Compare each Element of 2 Matrix for zero and non-zeroHi There,
I want to create a logical function that returns true if all non-zero elements in Matrix Z^2 are accompanied by non-zero (true) elements at the same locations in Z.
For example;
Z = [1,0,1;1,1,1;1,0,1]
Z^2 = [2,0,2;3,1,3;2,0,2]
From this basic example, every non-zero element in Z^2 is accompanied by a non-zero in Z. Hence the function output would be TRUE.
for i=1:N
for j=1:M
function output = ABC(Z)
output = (Z(i,j) & Z^2(i,j) ~= 0) then TRUE
end
or something to that effect.
Thanks, Xen Xenofon Antoniouhttps://in.mathworks.com/matlabcentral/profile/authors/16668220-xenofon-antonioutag:in.mathworks.com,2005:Question/4953602019-12-07T06:39:14Z2019-12-07T06:59:23ZHow to turn a camera webcam into a video.I want to get the value printed on video instead of webcam.
clear
camera = webcame; % Connect to the camera
==> camera = VideoWriter('slow.avi')
nnet = alexnet; % Load the neural net
while true
picture = camera.snapshot; % Take a picture
picture = imresize(picture,[227,227]); % Resize the picture
label = classify(nnet, picture); % Classify the picture
image(picture); % Show the picture
title(int(label)); % Show the label
drawnow;
end
I've changed it, but it doesn't work. What should I change?bo hyeoun leehttps://in.mathworks.com/matlabcentral/profile/authors/12394730-bo-hyeoun-leetag:in.mathworks.com,2005:Question/4953612019-12-07T06:46:47Z2019-12-07T06:46:47ZWhy is my response not changing despite changing the parameters on my feedforward controller? Please help. I am having an issue with simulink. I am changing the parameters for feedforward gain and feedforward time constants which are the coefficients of S for both numerator and denominator. I expected a chnage in the response of the graph under scope T(s) but I keep getting the same exact graph. Can you please help me debug this? What am I doing wrong.Tsubasa Watanabehttps://in.mathworks.com/matlabcentral/profile/authors/12035539-tsubasa-watanabetag:in.mathworks.com,2005:Question/2330562015-08-10T08:36:01Z2019-12-07T06:34:27Zpid controller with two input and single output responsex'(t) = Ax(t) + B*u(t)+Bphi*Uphi(t); y(t) = Cx(t) + Du(t); How to use two inputs in PID controller i.e u(t) and Uphi(t). Please tell the matlab program, if u(t) force input and Uphi(t) another input then implement PID controller to get y(t) response. MOHAMMAD AMIRhttps://in.mathworks.com/matlabcentral/profile/authors/6736415-mohammad-amirtag:in.mathworks.com,2005:Question/4950292019-12-05T13:58:10Z2019-12-07T06:27:48ZHow can I select a specific variable in the .mat file which contains different variables in the user interface?Hi!
I want to design an app which can draw with a .mat file. How can I select a specific variable in the .mat file which contains different variables in the user interface? By 'text area' or something?Kunpeng Zhanghttps://in.mathworks.com/matlabcentral/profile/authors/16831661-kunpeng-zhangtag:in.mathworks.com,2005:Question/4953552019-12-07T06:10:26Z2019-12-07T06:13:34ZEMG feature values are mixing Dear
I extracted feature of ZC, WL, MAV and ZC from EMG signals of different exercise like handopen, handclose etc. but features values are mixing/overlapping with each others so I classification accuracy is not good.
Kindly guide what i do with it?
find the snap shot of min and max values
Ali Asgharhttps://in.mathworks.com/matlabcentral/profile/authors/12644613-ali-asghartag:in.mathworks.com,2005:Question/4953542019-12-07T06:08:55Z2019-12-07T06:08:55ZClose a web browser from scriptI'm doing a project where I open a broswer (default browser is chrome) from matlab using...
url = 'www.google.com';
web(url)
That opens Chrome and now if I want to close the browser how would I do that.
For my project I'm opening a different page and pulling data from it but I need to open 60 variations of that page, so I'm looking for a way to not have 60 websites up when the program has finished running. Thank you for the help!!Seth Cottengimhttps://in.mathworks.com/matlabcentral/profile/authors/14639448-seth-cottengimtag:in.mathworks.com,2005:Question/4953512019-12-07T05:17:11Z2019-12-07T05:44:21ZNested for loops to optimize priceTesting various parameters to find the one that gives the most profit, through price equation:
Price = (0.12*P)-(Price of Reactor +0.04*M+1400000*Q). How to test all possible combinations of P, price of reactor, M, and Q to find the largest price/i.e. most profitable.
function Project = optimize(T)
T=[298.15:873.15];
length(T);
K=zeros(1,length(T));
myanswer=nan(2,length(T));
M=linspace(1,100,length(T));
Q=zeros(1,length(T));
Price=zeros(1,length(T));
for i=1:length(T)
K(i)=exp(-20000/(8.314*T(i)));
end
for j=1:length(T);
syms P
eqn = K(j)*M(j)^2-(2*M(j)*P*K(j))+(K(j)*P^2)-P;
myanswer(:,j)=solve(eqn);
myanswer(:,j)=double(myanswer(:,j));
end
P1=myanswer(1,:);
P2=myanswer(2,:);
r=linspace(2,100,length(T));
A=zeros(1,length(r));
for k=1:length(r)
A(k)=10*3.14*(r(k))^2;
Q(k)=25*3.14*r(k)^2*(T(k)-298.15);
end
Priceofreactor=A*150000;
Q=Q/0.12; %% accounts for 12% efficiency
P1=double(P1);
for d=1:length(T)
Price(d) = 0.12*P1(d)-(Priceofreactor(d)+0.04*M(d)+140*Q(d));
end
max(Price)
end
Yousif Alhammadihttps://in.mathworks.com/matlabcentral/profile/authors/14706658-yousif-alhammaditag:in.mathworks.com,2005:Question/4946972019-12-04T01:12:02Z2019-12-07T05:43:58ZHelp solving this problem?
I was wondering if anyone could lend me a hand in starting to solve this question? im relatively new to the program. Bailey Owen Bankshttps://in.mathworks.com/matlabcentral/profile/authors/16934057-bailey-owen-bankstag:in.mathworks.com,2005:Question/4953202019-12-06T23:17:27Z2019-12-07T05:38:09ZUsing a network license on personal computerHi, I seem to remember being able to use matlab on my personal computer associating user account with my organizational email but now microsoft won't let me associate my user account with my organizational email. Standardtrickynesshttps://in.mathworks.com/matlabcentral/profile/authors/5430322-standardtrickynesstag:in.mathworks.com,2005:Question/4953482019-12-07T03:55:19Z2019-12-07T05:32:18ZChoose my k-term from matrix and defines by itself on for loopSuppose i have n×1 matrix before, (column vector), namely "x1" (i'm defining this matrix with x1). I can't write my x1 because of it depends on my input. And this matrix could be 3×1, 7×1, until n×1. In this case i won't mention it on my script below
x1
for c=1:10
for d=0:9
'a',c,=x1(c,1)
end
end
My wish is when i have x1 is matrix of 10×1 (Look at my c) my for loop will display
a1=
2
a2=
3
.
.
.
a10=
4
2, 3, 4 are arbitrary numbers depend on my input of matrix x1. That means, i want it defines a variable by itself generating from my "c" (Look at my fourth line)
And that 'a',c, can be used for evaluating another formula.
For example
Px=a1+a2+a3
Is that possible?
Thanks. If my question is not clear, please tell me.
EDIT :
Another alternative in my thought is the following:
For example, i want to construct summation
$$\sum_{d=0}^{c}x1(c,1)\cdot x^d$$
My attempt is:
x1
for c=1:10
for d=0:9
P=sum((x1(c,1)))*9^d
end
end
But it's Not work and displays weird thing.
As i said before, actually my goal is evaluating the k-element in my matrix that is i take it randomly (not literally "random")
And construct it as like this:
$$P(x)=a_1x^0+a_2x^1+\cdots+a_nx^{n-1}$$
Where $a_1, a_2, a_n$ is the k-element from my matrix, and $x$ is just independent variable in that equation and depend on my input.
I've edit my question. I hope it's clear now and tell me if it's not. Thanks again.Fahmy Shandyhttps://in.mathworks.com/matlabcentral/profile/authors/11394573-fahmy-shandytag:in.mathworks.com,2005:Question/4953522019-12-07T05:17:46Z2019-12-07T05:17:46ZCan I plot a nomographic chart ,and how to add a line ...Hello I want to know to have a nomographic chart
Could let me know how to have this plot for example
by equation T =(1.84S +4.66)^0.37 (1.21R)^4/3
as the picture
hun chehttps://in.mathworks.com/matlabcentral/profile/authors/17042423-hun-chetag:in.mathworks.com,2005:Question/4951212019-12-05T23:03:14Z2019-12-07T05:17:41Zhow 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://in.mathworks.com/matlabcentral/profile/authors/13931295-muhammad-murtazatag:in.mathworks.com,2005:Question/4953252019-12-06T23:41:07Z2019-12-07T05:11:44ZTracking object in video and plot path of objectHello,
I have one video and in that video i am tracking a car's particular one point through the video and i got success in that one
but i want to plot that (point on a car) point's path at a same on video. How can i do that??
Please help me
thank you in adavanceMA khanhttps://in.mathworks.com/matlabcentral/profile/authors/16918966-ma-khantag:in.mathworks.com,2005:Question/4953502019-12-07T04:57:16Z2019-12-07T05:00:43Zhow save results?how save sevral results in same time like this in one term
save(z_room z_room1 z_room2 z_room3 z_room4 z_room5 z_room6 z_room7 z_room8 z_room9 z_room10 z_room11 z_room12 z_room13 z_room14 z_room15 z_room16 z_room17 z_room18 z_room19 z_room20 z_room21 z_room22 z_room23 z_room24 z_room25)abdullah qasimhttps://in.mathworks.com/matlabcentral/profile/authors/12485153-abdullah-qasimtag:in.mathworks.com,2005:Question/4835392019-10-04T05:01:00Z2019-12-07T05:00:20ZLinear programming for economic dispatchHi guys, i have this two generator equations and i want to use LINPROG to find the optimal power genion for each unit and get the lambda value given an equality constraint of p1+p2=220MW.
clc; clear all; close all;
load=220;
f=[0.2 3 0.175 3];erat
aeq=[1 1 1 1];
beq=load;
%lb=[0 0]
%ub=[500 0]
[x,fval]=linprog(f,[],[],aeq,beq,[],[])
This is what i have tried but its not working.
ThanksDivyesh Patelhttps://in.mathworks.com/matlabcentral/profile/authors/9793664-divyesh-pateltag:in.mathworks.com,2005:Question/4953472019-12-07T03:55:01Z2019-12-07T04:41:45ZHow do i set axis to only positive numbers for polyfit function How do i set axis to only positive numbers for polyfit function
I dont want the graph to continue into - y axis
thsnk Joseph Slatteryhttps://in.mathworks.com/matlabcentral/profile/authors/7620647-joseph-slatterytag:in.mathworks.com,2005:Question/4953352019-12-07T02:02:35Z2019-12-07T04:19:44Zquestion about vector multiplication The Matlab vector v1 has a dimension of n-by-1 and the vector v2 has a dimension of 1-by-n, which of the following is true?
A) The+operation v1*v2 does+not+return+an+error
B) The+operation v2*v1 does+not+return+an+error
C) The+operation v1.*v2 does+not+return+an+error
D) None+of+the+aboveJudy Zhuohttps://in.mathworks.com/matlabcentral/profile/authors/16736871-judy-zhuotag:in.mathworks.com,2005:Question/4952672019-12-06T17:30:01Z2019-12-07T04:06:46Zinserting vectors into another new vectorHello everybod,
Let’s say I have two vectors, A=[7 17 27] and B=[13 22], and later produce a new vector C as shown in the below process:
put the first number from A as the first number in C and put the first number form B as the second number in C and then put the second number from A as the third number in C then put the second number from B as the fourth number in C and keep going on the same process to the end.
That means, I should have the final result for C as [7 13 17 22 27].
Thank youMohanned Al Gharawihttps://in.mathworks.com/matlabcentral/profile/authors/9781703-mohanned-al-gharawitag:in.mathworks.com,2005:Question/4953382019-12-07T02:36:06Z2019-12-07T03:54:26ZHow to get cluster more than 2 if i have :Y1 = mvnpdf(X,mu1,sigma1);
Y2 = mvnpdf(X,mu2,sigma2);
Y3 = mvnpdf(X,mu3,sigma3);
Cluster1 = Y1 > Y2;
Cluster2 = ~Cluster1;
Cluster3 = ??????Steven Pranatahttps://in.mathworks.com/matlabcentral/profile/authors/16339813-steven-pranatatag:in.mathworks.com,2005:Question/4953412019-12-07T02:46:59Z2019-12-07T03:49:44ZI want the code to repeat for 10,000 times and add the new value to the matrix but I don't know how? Please help.This is my code so far and I added the "for k" and "end" in hopes of making the code loop but it didnt work. The goal of the project is to have values from 1-100 which start out with a value of 100 and then 2 are randomly selected from this group of 100. There is a random choosing of who wins and if they win, their value (100) gets a +1 applied to it. If they lose they get -1. I want 10,000 iterations where any number can be chosen.
nsims = 10000;
for k = 1:nsims
people = [1:100];
for i=1:100
people(i) = 100;
end
simsize = numel(people);
y = (randperm(simsize, 2));
if round(rand) == 0
output = y(2);
else
output = y(1);
end
win = people(y(1)) + 1;
lose = people(y(2)) - 1;
dist = [win; lose];
endVictor Popa-Similhttps://in.mathworks.com/matlabcentral/profile/authors/16941501-victor-popa-similtag:in.mathworks.com,2005:Question/4953462019-12-07T03:39:15Z2019-12-07T03:46:14Zbin_data=imbinarize(r_data);I use matlab 2018a , the code :
bin_data=imbinarize(r_data);
the error was
Undefined function or variable 'imbinarize'.
can anyone help me?
ansam nazarhttps://in.mathworks.com/matlabcentral/profile/authors/16974675-ansam-nazartag:in.mathworks.com,2005:Question/4953452019-12-07T03:20:33Z2019-12-07T03:30:22ZIndex in position 1 is invalid. Array indices must be positive integers or logical values.Getting the error
Index in position 1 is invalid. Array indices must be positive integers or logical values.
Error in Untitled (line 35) plot(x, Tdata(0,:));
when running. Cannot figure out how to make the plot work in the following script.
b = 0.0003;
a = 1.5;
d = 5.3;
c = 1.8;
R = 2/100; %m
Tr = -45; %degC
Ti = -30; %degC
N = 10;
x = linspace(-R,R,(2*N+1));
dx = x(2)-x(1);
T = zeros(size(x));
T = T + Ti;
T(1) = Tr;
T(end) = Tr;
Tdata = T;
dt = 1.8;
T1 = T;
T2 = zeros(size(T1));
ndt = 1800/dt;
for j = 1:ndt
T2(1) = Tr;
T2(end) = Tr;
for i=2; length(T2)-1;
T2(i) = T1(i) + dt/2/dx/dx/(c+d*T1(i))*((2*a+b*(T1(i+1)+T1(i)))*(T1(i+1)-T1(i))-(2*a+b*(T1(i-1)+T1(i)))*(T1(i)-T1(i-1)));
end
Tdata = [Tdata;T2];
T1=T2;
end
plot(x, Tdata(0,:));John Barrhttps://in.mathworks.com/matlabcentral/profile/authors/10890094-john-barrtag:in.mathworks.com,2005:Question/4953432019-12-07T03:12:26Z2019-12-07T03:25:15Zwhen installing matlab_doc_zh_CN_common,the following fault is detected: invalid distance too far backI encounter a problem when installing MATLAB 2019b in windows 7 service pack1. when the installation process was 42% done, a window jumped,that is: following fault detected when installing matlab_doc_zh_CN_common: invalid distance too far back. I have tried several solutions to solve this problem: temporarily disable any antivirus or security software. Then I shut down my fire-defend wall. But it did not work.ji wanghttps://in.mathworks.com/matlabcentral/profile/authors/15075827-ji-wangtag:in.mathworks.com,2005:Question/4953422019-12-07T03:06:44Z2019-12-07T03:22:46ZFunction: Compare each Element of 2 Matrix for zero and non-zeroHi All,
I am looking at writing a function for the below set of constraints.
We start with a matrix, Z
We want to compare zero and non-zero elements of Z and Z^2.
Hence, need to write a function that will return:
- True if all non-zero elements in a Matrix, Z^2, are accompanied by non-zero (true) elements at the same locations in matrix Z.
As an example:
Z = [1,0,1;1,1,1;1,0,1]
Z^2 = [2,0,2;3,1,3;2,0,2]
From this, we can see if we compare Z and Z^2 by element, all non-zero elements of Z^2 are accompanied by non-zero in Z.
Hence, the function, would be TRUE.
Xenofon Antoniouhttps://in.mathworks.com/matlabcentral/profile/authors/16668220-xenofon-antonioutag:in.mathworks.com,2005:Question/4951592019-12-06T04:07:03Z2019-12-07T03:09:33Zsurface fixed point value ZDear
I want to know the value of Z from the surfc function
That is when I give the value of x, y
It gives me the value of z
surfc (x, y, z)abdullah qasimhttps://in.mathworks.com/matlabcentral/profile/authors/12485153-abdullah-qasimtag:in.mathworks.com,2005:Question/4953142019-12-06T22:54:12Z2019-12-07T03:07:34ZX Y grids on 2D surface plotI'm facing problem in making visible the grids for the x and y axis.
Her is a simple exemple:
[X,Y,Z] = peaks(25);
surf(X,Y,Z)
shading interp;
grid on
view(2)
Please, any help?Toufikhttps://in.mathworks.com/matlabcentral/profile/authors/17041412-toufiktag:in.mathworks.com,2005:Question/4953402019-12-07T02:46:52Z2019-12-07T03:05:39ZIndices on the left side are not compatible with the size of the right sideI'm trying to get something to plot, but get the error message "unable to perform assignment because the indices on the left side are not compatible with the size of the right side" at the Va(n) part (4th line up from end of the loop). I'm thinking that this is because n are integers and t isn't? Or is it something else that's gone wrong?
%begin with specifying constants
AB=0.6;
BC=0.1;
BG=0.08;
AG=AB-BG;
omega=120*pi; %for now since there is no angular accel, omega is constant
%two revolutions at 120pi rpm takes 1/30 seconds
for n=1:10000
t=linspace(0,1/30, 10000)
theta=omega.*t; %assuming theta starts at 0
%since Vb=Vc+Vbc,
Vbx=omega.*BC.*sin(theta);
Vby=omega.*BC.*cos(theta);
%using trig:
Vb=omega*BC;
%let zetaAB=zeta*k (the unit vector) where zeta is some unknown
%using sine rule with AB and BC:
zeta=omega*(cos(theta)/sqrt(36-sin(theta).^2));
%let tau=angle CAB
tau=acos(sqrt(36-sin(theta).^2)/6);
%since Va=Vb+Vab
%Vax=omega*BC*sin(theta)+zeta*AB*sin(tau)
%Vay=omega*BC*cos(theta)-zeta*AB*cos(tau)
%Vay=0 because there is no vertical movement at A, only horizontal so
%Vax=Va
%rearranging for zeta then subbing into Vax (along with AB) gives:
Va(n)=0.1.*omega.*sin(theta).*(1+(cos(theta))./sqrt(36-sin(theta).^2));
%Vg can be found in a similar fashion to be:
Vg(n)=sqrt((Va-zeta.*AG.*sin(tau))+zeta.*AG.*cos(tau));
end
%plot the graph
plot(t,Va,t,Vg)
xlabel("time elapsed (s)")
ylabel("magnitude (m/s)")
axis tight
grid on
title('Task 1, Part a')Elizabeth Nghttps://in.mathworks.com/matlabcentral/profile/authors/14844747-elizabeth-ngtag:in.mathworks.com,2005:Question/4953332019-12-07T01:59:25Z2019-12-07T02:52:51Z'Store the first N (user enters N) Fibonacci numbers in a row vector.'I know how to get user entered number of fibbonachi numbers. But I don't know how to show them in a row vector.clc;
clear;
close all;
N=input('Enter the number = ');
B(1)=0;
B(2)=1;
count=1;
for i=3:N
B(1,i)=B(i-2)+B(i-1);
end
disp(B)Lakshan Bandarahttps://in.mathworks.com/matlabcentral/profile/authors/14612195-lakshan-bandaratag:in.mathworks.com,2005:Question/3466802017-06-28T23:45:29Z2019-12-07T02:45:54ZMy data is x,y,z,w. How can I create a 3D contour plot of it?I have a tab delimited text file (see attached) that has x,y,z data from a design of experiments sweep and the output variable is w.
I tried using this:
fidi=fopen('DOE sweep1A.txt', 'rt'); % version of text file without headers
D=textscan(fidi, %f%f%f%f');
X=D{1}; % rpm
Y=D{2}; % m_dot
Z=D(3); % P
W=D{4); % Power
N=100;
Xi=linspace(min(X),max(X),N);
Yi=linspace(min(Y),max(Y),N);
Zi=linspace(min(Z),max(Z),N);
[Gx,Gy,Gz]=meshgrid(Xi,Yi,Zi);
Wi=griddata(X, Y, Z, W, Gx, Gy, Gz, 'natural');
contour(Gx, Gy, Gz, Wi, 'Linestyle', '-', 'Linecolor', [0 0 0], 'ShowText', 'on', 'LevelStep', 1)
grid on
colormap(jet)
colorbar;
And I know that it doesn't work because it can only have 2 dimensions and also that there are repeating numbers for X, Y, and Z because it is a design of experiments sweep.
But I would still want to plot this preferably in a 3D contour plot.
Is there a way to do so?
Thanks.Ewen Chanhttps://in.mathworks.com/matlabcentral/profile/authors/193071-ewen-chantag:in.mathworks.com,2005:Question/4953362019-12-07T02:06:57Z2019-12-07T02:45:25ZHow to force reshape for change elements? m=input('z= ');
n=m+1;
for i=1:n
x(i)=input(['x',num2str(i),'= '])
for k=0:m
x1=x(i)^k;
end
end
x=reshape(x1,n,n)
But it displays Error using Reshape because my elements are change.
My goal is to reshape my input becomes n×n matrices.
When i tried to change
x=reshape(x1,n,[])
For example i input z=2
And input each one,
x1=1
x2=2
x3=3
This just display
x=
1
2
3
But i "want" my result is like this
x=
1 1 1
1 2 4
1 3 9
Notice that in my first column, i raised them to zero, (1^0=1, 2^0=1, 3^0=1)
In my second column, i raised them to one, (1^1=1, 2^1=2, 3^1=3).
And in my last column i squared them as
(1^2=1, 2^2=4, 3^2=9)
How to process this become possible?Fahmy Shandyhttps://in.mathworks.com/matlabcentral/profile/authors/11394573-fahmy-shandytag:in.mathworks.com,2005:Question/4953392019-12-07T02:42:09Z2019-12-07T02:42:09ZFinite difference method 1st degreeI have to solve this problem using a first degree finite difference method. I am really struggling to understand what is not working with my code. If someone could take a look at ir and explain to me what<s wrong I would really appreciate it. Here is the assignement and the code below
function[y]=problimite(N,P,Q,R, a, b, alpha, beta)
h=(b-a)/(N+1);
S=-1+P(1:end-1)*h/2;
D=2+Q(1:end)*h^2;
I=-1-P(2:end)*h/2
B=[(-R(1)*(h^2)+(1+P(1)*h/2))*alpha,-R(2:end-1).*h^2,-R(end)*(h^2)+(1+P(end)*h/2)*beta];
disp(S)
y = tridiagonal(N, S, D, I, B);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5
function y = tridiagonal(N, S, D, I, B)
y(1)=B(1)/D(1);
for i=2:N
S(i-1)=(S(i-1))/D(i-1);
D(i)=D(i)-I(i-1)*S(i-1);
y(i)=(B(i)-I(i-1)*y(i-1))/D(i);
end
x(N)=y(N);
for i=N-1:1
x(i)=y(i)-S(i)*x(i+1);
end
%%script%%%%
b=1;
alpha=0;
beta=1;
X=[0.9:0.01:1];
p=@(x) -1/x;
q=@(x) 0;
r=@(x) (1.6)/(x^4);
N=9;
P=arrayfun(p,X);
R=arrayfun(r,X);
Q=arrayfun(q,X);
%h=.01;
%I=[-1-P(2:end)*h/2]
%D=[2+Q(1:end)*h^2]
%S=[-1+P(1:end-1)*h/2]
%display(P);
%display(R);
%display(Q);
plot(problimite(N,P,Q,R, a, b, alpha, beta))
hold on
%% partie 2 %%
X=[0.9:0.005:1];
p=@(x) -1/x;
q=@(x) 0;
r=@(x) (1.6)/(x^4);
N=19;
P=arrayfun(p,X);
R=arrayfun(r,X);
Q=arrayfun(q,X);
%display(P);
%display(R);
%display(Q);
plot(problimite(N,P,Q,R, a, b, alpha, beta))
Patirick Legarehttps://in.mathworks.com/matlabcentral/profile/authors/14538014-patirick-legaretag:in.mathworks.com,2005:Question/4951102019-12-05T21:00:53Z2019-12-07T02:37:40ZHow 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://in.mathworks.com/matlabcentral/profile/authors/15571509-ajinkya-bankartag:in.mathworks.com,2005:Question/4951352019-12-06T01:06:47Z2019-12-07T02:34:11ZSTROOP 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://in.mathworks.com/matlabcentral/profile/authors/16451453-tanitoluwa-femi-idowutag:in.mathworks.com,2005:Question/3522992017-08-10T14:25:43Z2019-12-07T02:25:45ZHow does MATLAB compute the covariance of a complex array?I'm working with a complex array and looking at the covariance matrix and the relation matrix. (The explanation of these matrices can be found here: https://en.wikipedia.org/wiki/Complex_normal_distribution.) When I am compute the covariance matrix using cov(), the matrix looks more like the relation matrix. Consider a toy example:
>> u = [1 + 1i, 2 + 1.5*1i;1 + 2*1i,3+1i;3+1.5*1i,1+1.5*1i]
u =
1.0000 + 1.0000i 2.0000 + 1.5000i
1.0000 + 2.0000i 3.0000 + 1.0000i
3.0000 + 1.5000i 1.0000 + 1.5000i
>> cov(u)
ans =
1.5833 + 0.0000i -1.1250 - 0.0833i
-1.1250 + 0.0833i 1.0833 + 0.0000i
>> 0.5*(u-mean(u))' * (u-mean(u))
ans =
1.5833 + 0.0000i -1.1250 - 0.0833i
-1.1250 + 0.0833i 1.0833 + 0.0000i
>> 0.5*conj((u-mean(u))') * (u-mean(u))
ans =
1.0833 + 0.0000i -0.8750 + 0.4167i
-0.8750 + 0.4167i 0.9167 - 0.5000i
The second method of computing the covariance matrix is basically what MATLAB is doing. However, according to the above Wiki article, this is the relation matrix, not the covariance matrix. The third method of computing the covariance matrix is how MATLAB claims to compute the convariance matrix as can be seen in its Help documentation on cov(). However, the results are clearly different.
So my question is: How does MATLAB actually comput the covariance matrix? I don't think it actually uses the conjugate transpose, but rather only uses the transpose.njj1https://in.mathworks.com/matlabcentral/profile/authors/4297820-njj1tag:in.mathworks.com,2005:Question/4953372019-12-07T02:23:08Z2019-12-07T02:24:48Zhow to solve a multiple objective nonlinear programming problemI do not know how to solve a multiple objective nonlinear programming problem.Are there any toolbox or algorithms in MATLAB ?jordan michelhttps://in.mathworks.com/matlabcentral/profile/authors/14166440-jordan-micheltag:in.mathworks.com,2005:Question/4953162019-12-06T22:57:29Z2019-12-07T02:22:14ZHow to ignore an error inside the fitness fuction?I'm using a non convex function in my optimization problem whith genetic algorithms.
For a value be acepted in my problem I have a initial condition that must be respected. If it is respected then the fitness function is checked.
So, I created a function to check this condition inside the fitness function. When this condition is not reached I assigned a large score to the variable tested. But this score is changing the mean.
Is there a way to supress the influence of this value in the mean or ignore it and go to the next iteration ?
Like when we are using a 'for' and write 'continue' to go to the next loop. Is there a command like this in Optimization toolbox?
Leonardo Abranteshttps://in.mathworks.com/matlabcentral/profile/authors/10083928-leonardo-abrantestag:in.mathworks.com,2005:Question/4953302019-12-07T01:37:43Z2019-12-07T02:14:08Zwlan toolbox is incompletedI use the wlan toolbox to transmit an image,but the function called wlanClosestReferenceSymbol can't be found,how can I solve this problem?yuchao shawhttps://in.mathworks.com/matlabcentral/profile/authors/16628782-yuchao-shawtag:in.mathworks.com,2005:Question/4952322019-12-06T13:46:10Z2019-12-07T02:02:34ZHow do I use splitapply when the applied function has non-scalar output?I am trying clean variables in a dataset, creating a new table variable, but splitapply does not seam to allow for nonscalar outputs of the function.
As a minimal working example, I have a table
myTable = table();
myTable.Gender = ["Male","Female","Male","Female"]';
myTable.Var1 = [1,2,3,4]';
And I am now trying to create a new table variable where the group mean is subtracted from "Var1" (yielding Var2 = [-1, -1, 1, 1])
When using splitapply(), I get the error
Error using splitapply (line 132)
The function '...' returned a non-scalar value when applied to the 1st group of data.
Is there a way to do this, also for function more involved than demeaning the input variables?
Thanks in advance,
Chrisclauperhttps://in.mathworks.com/matlabcentral/profile/authors/9542205-clauper