https://uk.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2018-12-15T04:33:58Ztag:uk.mathworks.com,2005:Question/4358592018-12-15T03:54:58Z2018-12-15T04:33:58ZGet the probability of a matricesI have a matrix E1
1 1 4 5 1 1 3 1
1 1 2 5 1 1 1 1
3 4 1 3 5 10 5 4
4 2 3 4 5 8 4 1
1 2 12 16 1 1 3 3
1 2 10 14 1 1 1 1
1 1 10 8 2 5 3 15
5 2 1 3 2 21 1 11
I sort the symbols into a table
%calculate the freq%
[a,b]=hist(E1,unique(E1));
out=[b' sum((a),2)];
%Sorting into table%
Table = array2table(out,'VariableNames',{'Symbol','Count'})
%Rearrange table in descending order%
tblB = sortrows(Table,{'Count'},{'descend'})
And the result turns into this
Symbol Count
______ _____
1 25
3 8
2 7
5 7
4 6
10 3
8 2
11 1
12 1
14 1
15 1
16 1
21 1
So my question is how can I get the probabilities of each symbols in vector?
The desired result is as below
mat=[0.3906 0.125 0.1094 0.1094 0.0938 0.0469 0.0313 0.0156 0.0156 0.0156 0.0156 0.0156 0.0156];fyza affandihttps://uk.mathworks.com/matlabcentral/profile/authors/13676165-fyza-affanditag:uk.mathworks.com,2005:Question/4345642018-12-08T10:54:10Z2018-12-15T04:33:41ZHow to test only one row ?Hi, I have code for test data the result between ttes and pred_tes is equivalent. The code like below :
load datates4.mat
xtes = cell2mat(Input); %55x25
load classtes4.mat
ttes = cell2mat(Target); %55x1
load W1tes4.mat % 25x900
load B1tes4.mat % 1 x 900
load W2tes4.mat % 900 x 11
load B2tes4.mat % 1 x 11
num_example = size(xtes,1);
D = size(xtes,2);
%% preprocessing data xtes
for col = 1: D
xtes(:,col)=double(xtes(:,col)-mean(xtes(:,col)));
end
for col = 1: D
xtes(:,col)=double(xtes(:,col)/std(xtes(:,col)));
end
%% process testing
Z_tes = bsxfun(@plus, xtes*W1, B1);
hidden_tes = max(0,Z_tes);
scores_tes = bsxfun(@plus, hidden_tes*W2, B2);
for row = 1:num_example
[maxi,tes]=max(scores_tes(row,:));
pred_tes(row,1) = tes;
end
acc_tes =sum(pred_tes==ttes)/num_example*100;
Now I want only test one row, where the input is value feature extraction from the image I input, But the result I get is not equivalent with the target I want and I always get same result for another image I input. Please help me to fix my code, Which one in my code below not right? I get difficult when I want make code which read only one image. Thanks.
Here I attach my code ;
x = input; %1 x25
load W1tes4.mat % 25x900
load B1tes4.mat % 1 x 900
load W2tes4.mat % 900 x 11
load B2tes4.mat % 1 x 11
% load classtes4.mat
% ttes = cell2mat(Target); %55x1
num_example = size(x,1);
D = size(x,2);
%% preprocessing data xtes
% x = (x-min(x))/(max(x)-min(x));
% x = (x - mean(x))/std(x);
for col = 1: D
x(col)=double(x(col)-mean(x(col)));
end
for col = 1: D
x(col)=double(x(col)/std(x(col)));
end
%% proses testing
Z_tes = bsxfun(@plus, x*W1, B1);
hidden_tes = max(0,Z_tes);
scores_tes = bsxfun(@plus, hidden_tes*W2, B2);
for row = 1:num_example
[maxi,tes]=max(scores_tes(row,:));
tes(row,1) = tes;
end
tes = round(tes);
if (tes==1)
resulttesting='Psidium Guajava';
elseif (tes==2)
resulttesting='Phaleria Macrocarpa';
elseif (tes==3)
resulttesting='Piper Sp';
elseif (tes==4)
resulttesting = 'Piper Betle L.';
elseif (tes==5)
resulttesting = 'Phyllantus Acidus';
elseif (tes==6)
resulttesting = 'Erythrina Hypaphorus';
elseif (tes==7)
resulttesting = 'Glycosmis Sp';
elseif (tes==8)
resulttesting = 'Jasminum Sambac';
elseif (tes==9)
resulttesting = 'Centella Asiatica';
elseif (tes==10)
resulttesting = 'Hibiscus Rosa-sinensis L';
else resulttesting = 'Alstonia Scholaris';
end
disp(['Classification= ',resulttesting]);
Oman Wisnihttps://uk.mathworks.com/matlabcentral/profile/authors/13491522-oman-wisnitag:uk.mathworks.com,2005:Question/4358552018-12-15T01:35:49Z2018-12-15T04:33:22Zlicense manager error -103How can I fix this error and run the program againPeter chuhttps://uk.mathworks.com/matlabcentral/profile/authors/14370109-peter-chutag:uk.mathworks.com,2005:Question/4358502018-12-14T23:22:41Z2018-12-15T04:31:37ZHow to find FWHM from a gauss4?Hello!
I am using 'gauss4' to extract the FWHM from an array of x and y values. How to proceed?
Thanks!
Tomojit Chowdhuryhttps://uk.mathworks.com/matlabcentral/profile/authors/7689940-tomojit-chowdhurytag:uk.mathworks.com,2005:Question/4358232018-12-14T19:15:09Z2018-12-15T04:31:35ZProblem with a purchased toolbox QFTCTDear all,
I had purchased a Quantitative feedback control toolbox from codyPower,
upon adding it to MATLAB through setpath, i am getting the following error:
can anyone please provide the solution.
my system configuration details are"
Version: '1.1.0'
Vendor: 'Microsoft Corporation'
Renderer: 'GDI Generic'
MaxTextureSize: 1024
Visual: 'Visual 0x18, (RGB 24 bits (8 8 8), Z depth 16 bits, Software, Single buffer, Antialias 0 samples)'
Software: 'true'
HardwareSupportLevel: 'none'
SupportsGraphicsSmoothing: 0
SupportsDepthPeelTransparency: 0
SupportsAlignVertexCenters: 0
Extensions: {3×1 cell}
MaxFrameBufferSize: 0
When i am typing the command as per the instruction manual
QFTCT
The error is coming as below:
Index exceeds the number of array elements (52).
Error in DefinePlant
Error in DefinePlant
Error in gui_mainfcn (line 220)
feval(gui_State.gui_OpeningFcn, gui_hFigure, [],
guidata(gui_hFigure), varargin{:});
Error in DefinePlant
Error in QFTCT
Please helpVargil Kumarhttps://uk.mathworks.com/matlabcentral/profile/authors/1674276-vargil-kumartag:uk.mathworks.com,2005:Question/4358532018-12-15T00:46:43Z2018-12-15T04:29:15ZHow can I evaluate the double integral of a piece-wise function and get a numerical answer, instead of the rewritten integral?pieclc;
clear;
R0plus = input('Entera value for R0+');%%Might have to change to syms%%%
syms yplus;
rplus = R0plus-yplus;
kappa=0.4;
yplusn=11;
%%if statements%%%%Reichardt (1951)%%
%syms Eoverv
Eoverv = piecewise(yplus<=50, 0.4*(yplus-(11*tanh(yplus/11))), yplus>50,(0.4/3)*yplus.*(0.5+(((R0plus-yplus)/R0plus)^2)).*(1+((R0plus-yplus)/R0plus)) );
up= (R0plus-yplus)./(Eoverv-1);
q= int(up,yplus, [0 yplus]);
uplus=(q./R0plus);
um = uplus.*(R0plus-yplus);
syms umplus;
umplus=int(um,yplus,0,R0plus)
subs(umplus)
The result is int(-(int((yplus - 10)/((22*tanh(yplus/11))/5 - (2*yplus)/5 + 1), yplus, 0, yplus)*(yplus - 10))/10, yplus, 0, 10).
I need the result of the integral not the problem rewritten. I should be given a numerical answer.Armando Gamezhttps://uk.mathworks.com/matlabcentral/profile/authors/14165222-armando-gameztag:uk.mathworks.com,2005:Question/4355432018-12-13T11:23:29Z2018-12-15T04:19:30ZHow to interpret statistics from glmfitI did a logistic regression for binomial data and the stats obtained are attached with this. I am getting avery hard time to understand the statisitics. Why there are two p-values and what does it signify?
Hari krishnanhttps://uk.mathworks.com/matlabcentral/profile/authors/13142902-hari-krishnantag:uk.mathworks.com,2005:Question/4358602018-12-15T03:56:58Z2018-12-15T04:18:50Zi need to display 'abc' using ASCII table but when i write char97:98:99 i only get 'a'. how do i get abc?i need to display 'abbc' from ASCII table. How do i do that?Jasmin Akter Promihttps://uk.mathworks.com/matlabcentral/profile/authors/13471074-jasmin-akter-promitag:uk.mathworks.com,2005:Question/4356822018-12-14T05:30:44Z2018-12-15T04:07:45Zwhen i use tripleangle command in matlab it doesnot answer?hi.i have installed robotics toolbox recently.when use commands from robotics,vision and control (peter corke) it is correct but when i use tripleangle command (paper 38,second eddition) there is this error:
Undefined function or variable 'tripleangle'.
how can i fix this this?Najmeh Eskandarihttps://uk.mathworks.com/matlabcentral/profile/authors/12493981-najmeh-eskandaritag:uk.mathworks.com,2005:Question/4352762018-12-12T03:45:36Z2018-12-15T04:06:50ZHow to load and display the text from a .mat file into GUIDE?I am trying to create a static text box that displays the variables from the .mat file. Then from that point on, every time the pushbutton1 is clicked the static text box displays the next variables in the same column up.
For example when I load the .mat file into GUI for the first time the static text box displays the text in box '1,1'. Then I press the pushbutton it will display the text in box '2,1' and so on.
This GUI will be compiled to be a standalone application to be used by users that do not have MATLAB installed.
Is this possible?Rae Cheonghttps://uk.mathworks.com/matlabcentral/profile/authors/14030620-rae-cheongtag:uk.mathworks.com,2005:Question/4358192018-12-14T18:56:44Z2018-12-15T03:32:55ZIdentify shape in binary picture make it smooth and ignore resti am trying to identify forged parts of an image and i am having results like the picture below.
How can i :
identify the bigest object in the picture
make borders for the object and fill it in, in order to be smooth
remove any remaining part from the image
in which direction should i go?
lvashttps://uk.mathworks.com/matlabcentral/profile/authors/13643452-lvastag:uk.mathworks.com,2005:Question/4358062018-12-14T17:54:01Z2018-12-15T03:23:17ZGUI with or without GUIDEI am making a GUI. I would like to make it programatically (not using GUIDE) because not GUIDE GUI files make alot more sense, I can read them and understand what is happenig. Am I going to miss out on something by making GUI without GUIDE? I'm not doing anything too complicated: grabbing some frames from a video camera displaying them and doing some math with them. I hope compile the final product into its own app. Am I going to encounter some problem I am not currently seeing by avoiding GUIDE?jwhttps://uk.mathworks.com/matlabcentral/profile/authors/12401768-jwtag:uk.mathworks.com,2005:Question/4358422018-12-14T21:42:33Z2018-12-15T03:18:12Zplot solution of linear systems (linsolve)Hello.
I am looking for a code that will help me plot a graph of solution of these two linear systems. My codes are the following, however, how can I get a solution into one plot with lines representing solution for each equation?
𝑥 +𝑦 +𝑧 = 2
𝑥 +2𝑦 −𝑧 = 4
−𝑥 +2𝑦 +𝑧 = 2
% LS for A
A = [1 1 1; 1 2 -1; -1 2 1];
a = [2; 4; 2];
linsolve(A,a)
plot ????
Katerina Marie Simkovahttps://uk.mathworks.com/matlabcentral/profile/authors/13799733-katerina-marie-simkovatag:uk.mathworks.com,2005:Question/4355352018-12-13T10:09:53Z2018-12-15T03:16:15Zhow to plot graph without intersection?I have this graph
E=[1 2;1 5;2 3;2 4;2 5;3 4;4 5;4 7;4 9;5 6;6 11;6 12;6 13;7 8;7 9;9 10;9 14;10 11;12 13;13 14]
when I use graph code,
G=graph(E(:,1),E(:,2))
h=plot(G)
plots graph with intersection.
Is there any codes that plot graph without intersection?Naime Ahmadihttps://uk.mathworks.com/matlabcentral/profile/authors/13711668-naime-ahmaditag:uk.mathworks.com,2005:Question/4358572018-12-15T02:02:14Z2018-12-15T03:15:01ZI use Matlab2018b on iOS. csvread does not work. file not foundi use this code
validdatatypes = {'.csv'};
strPath = dir('/Users/***/mess1600');
lPath = struct2cell(strPath)';
lPath = lPath(cell2mat(lPath(:,strcmp('isdir',fieldnames(strPath)))) == 0 & contains(lPath(:,1),validdatatypes),:);
lPath = cellfun(@(a,b) [b '\' a],lPath(:,1),lPath(:,2),'uniformoutput',0);
format long;
data = cell(numel(lPath),1);
for n = 1:numel(lPath)
data{n} = csvread(lPath{n},3,0);
end
error is:
Error using csvread (line 35)
File not found.
Error in export (line 10)
data{n} = csvread(lPath{n},3,0);
anybody got an idea? it worked on windows bennhttps://uk.mathworks.com/matlabcentral/profile/authors/14158990-benntag:uk.mathworks.com,2005:Question/4356712018-12-14T02:49:44Z2018-12-15T02:59:05ZHow to concatenate multiple files with 2 cell arrays each into one file in such way as the first cell array from the first file will go to the first column the second to the second column and so on in numerical order using for loop is fine...Hi, there, I'm relatively inexperienced in matlab, and programming overall. So my code lower on the page may be dumb...
I'm trying to take in multiple files with 2 arrays of numbers each and concatenate all of them into a single file so first cell array from the first file will go into the first column in the new file, the second array from the first file will go into the second column of the new file. The first array from the second file will go into the third column of the new file, the second array of the second file will go into 4th column of the new file and so on...
Trying to think about the solution with for loop, not really works...
Any help is appreciated, thanks.
for i=1:length(Files)
if (i == 1)
tmp = load(Files{i},'-mat');
S(i).data1 = tmp.data1;
S(i).data2 = tmp.data2;
Data1{i} = S(i).data1;
Data1{i+1} = S(i).data2;
else
tmp = load(Files{i},'-mat');
S(i).data1 = tmp.data1;
S(i).data2 = tmp.data2;
Data1{i+1} = S(i).data2;
endRGhttps://uk.mathworks.com/matlabcentral/profile/authors/10431558-rgtag:uk.mathworks.com,2005:Question/4356962018-12-14T07:37:19Z2018-12-15T02:58:54ZHow can I detect that which squares are ticked in the image?How can I detect that which squares are ticked in the image?
I'm think use the normxcorr2 or imshowpair to compare the original image with ticked image, but I not sure how to do this.
Original Image:
AlexMThttps://uk.mathworks.com/matlabcentral/profile/authors/8178244-alexmttag:uk.mathworks.com,2005:Question/4358582018-12-15T02:29:41Z2018-12-15T02:33:27ZIllegal use of reserved keyword ifHi all!
I am a beginner user of Matlab.
It is working fine but now every time I launch the code I receive
Error: File: rdannkeyword.m Line: 4 Column: 13
Illegal use of reserved keyword "if".
why? What can I do?
Thank you!
The first one is the code that i'm using, the second one is the file error
ann = uigetfile('*.ann');
in.fname = uigetfile ('*.unw.grd');
[file,path] = uiputfile('*.tif','File Saving',in.fname);
saveposition = fullfile(path,file);
in.width= str2double(rdannkeyword(ann,'Ground Range Data Longitude Samples'));
in.lines= str2double(rdannkeyword(ann,'Ground Range Data Latitude Lines'));
ann = uigetfile('*.ann');
function [value]=rdannkeyword(ann, pass)
value = [] if keyword is not found
% -------------------------------------------------------------
% LIUZ Mar-2011 original version
end
end
function [value]=rdannkeyword(annfile, keyword);
checkfile(annfile);
%
value=deal([]);
fid=fopen(annfile);
while ~feof(fid)
line=fgetl(fid);
if ~isempty(strfind(line,keyword))
a=textscan(line,'%s','delimiter','=');
%value=a{1}{end};
b=textscan(a{1}{2},'%s','delimiter',';');
value=b{1}{1}; % to get the value just after the = sign (the 'end' cell value might be part of the comment)
break
end
end
fclose(fid);
if isempty(value)
disp([keyword ' can not be found! Check!']);
end
end
Emanuele Melehttps://uk.mathworks.com/matlabcentral/profile/authors/11540697-emanuele-meletag:uk.mathworks.com,2005:Question/4358562018-12-15T01:44:24Z2018-12-15T02:04:18Zi am getting an error stating not enough input arguments someone please check through it for my mistakesfunction[Filterd_Output_Sig,Filt_Nuem,Filt_Denomi] = LPBUTTERFRAC(Msg_bits,Freq_Cutoff,Sam_Frequ,Fil_Order); %error : not enough input arguments
Freq_Nyquist = Sam_Frequ/2;
Non_Dimen_Freq=Freq_Cutoff/Freq_Nyquist;
[Filt_Nuem,Filt_Denomi]=butter(Fil_Order,Non_Dimen_Freq,'low'); % Filter Construction
Filterd_Output_Sig=filtfilt(Filt_Nuem,Filt_Denomi,Msg_bits);
LPF_Par_Order=1;
[Filterd_Output_Sig,Filt_Nuem,Filt_Denomi] =LPBUTTERFRAC(Msg_bits,1000,Freq_Step,5);
[Error_Mag_L,Error_Resp_L] = freqz(Filt_Nuem,Filt_Denomi,256,Freq_Step);
figure(2)
Error_Mag_Frac=angle(Error_Mag_L)*LPF_Par_Order;
plot(Error_Resp_L,Error_Mag_Frac,'r');
LPF_Par_Order=1.2;
[Filterd_Output_Sig,Filt_Nuem,Filt_Denomi]=LPBUTTERFRAC(Msg_bits,1000,Freq_Step,5);
[Error_Mag_L,Error_Resp_L] = freqz(Filt_Nuem,Filt_Denomi,256,Freq_Step);
figure(2)
Error_Mag_Frac=angle(Error_Mag_L)*LPF_Par_Order;
plot(Error_Resp_L,Error_Mag_Frac,'b');
LPF_Par_Order =1.4;
[Filterd_Output_Sig,Filt_Nuem,Filt_Denomi] =LPBUTTERFRAC(Msg_bits,1000,Freq_Step,5);
[Error_Mag_L,Error_Resp_L] = freqz(Filt_Nuem,Filt_Denomi,256,Freq_Step);
figure(2)
Error_Mag_Frac=angle(Error_Mag_L)*LPF_Par_Order;
plot(Error_Resp_L,Error_Mag_Frac,'g');
hold on
LPF_Par_Order =1.6;
[Filterd_Output_Sig,Filt_Nuem,Filt_Denomi]=LPBUTTERFRAC(Msg_bits,1000,Freq_Step,5);
[Error_Mag_L,Error_Resp_L] = freqz(Filt_Nuem,Filt_Denomi,256,Freq_Step);
figure(2)
Error_Mag_Frac=angle(Error_Mag_L)*LPF_Par_Order;
plot(Error_Resp_L,Error_Mag_Frac,'y');
axis on
grid on
legend('order 1','order 1.2','order 1.4','order 1.6');
title('Error Response of Fractional Low Pass Filter')
xlabel('Frequeny');
ylabel('Error Magnitude(dB)');taraneenadh bammidihttps://uk.mathworks.com/matlabcentral/profile/authors/10520236-taraneenadh-bammiditag:uk.mathworks.com,2005:Question/4339602018-12-05T10:28:38Z2018-12-15T01:38:50Zhow to remove the pixels under the curve on imageI have attatche my image.Sulochana Shttps://uk.mathworks.com/matlabcentral/profile/authors/12860494-sulochana-stag:uk.mathworks.com,2005:Question/4358542018-12-15T01:29:10Z2018-12-15T01:29:10ZUse Simulink to plot the cantilever’s tip deflection when a voltage v_a= 120·e‒2t·sin(200t) V is applied to the PZT block for a piezoelectric constant d= 4 x 10^-10 m/VI am really confuse on how to model this in simulink. I would really love some help solving this.Aryan Azarsepandanhttps://uk.mathworks.com/matlabcentral/profile/authors/11368256-aryan-azarsepandantag:uk.mathworks.com,2005:Question/4358082018-12-14T18:03:42Z2018-12-15T01:05:04Zhow can solve breakingpoint in simulink ? hi,
I am using SIMULINK, and I keep seeing this error
"The problem occurs at element 3. Change the breakpoints data or use the fixed-point tools such as Auto Scaling or Fixed-Point Advisor to determine a different parameter dialog type".
when i change "cp1,cp2,cp3,cp4" in my code :
i saw this problem
By the way,
my max step size=0.02;
min step size= auto
relative tolerance=1e-3
absolute tolerance=auto
solver=ode45, variable step
er=40;
cp1=0.833*10^6; cp2=1.67*10^6; cp3=7.84*10^6; cp4=14.7*10^6;
lookup_in=[0 (cp1+cp2)/2 (cp1+cp2)/2+er*eps (cp2+cp3)/2 ...
(cp2+cp3)/2+er*eps (cp3+cp4)/2 (cp3+cp4)/2+er*eps 100];
lookup_out=[cp1 cp1 cp2 cp2 cp3 cp3 cp4 cp4];
can anyone please help me with that ?
thanks in advance,
ADNAN KIRALhttps://uk.mathworks.com/matlabcentral/profile/authors/12274816-adnan-kiraltag:uk.mathworks.com,2005:Question/1839692015-03-19T08:53:47Z2018-12-15T01:04:20ZCalculate centerline in 3d StructureHi all,
I have a 3D-matrix of a segmented (pathological) trachea. The 3D-matrix consists of multiple binary slices. Using the surface function I construct a 3D-visualization of the trachea:
<</matlabcentral/answers/uploaded_files/27466/trachea.png>>
I'm interested in the diameter of the trachea throughout its course in the, at this moment I use regionprops to calculate the diameter for each slice in the xy-plane. But as you can see the structure is curved, so this causes me to overestimate the diameter at the portions of the trachea with a lot of deviation. I think I need to calculate a 3d-centerline and then calculate the diameter perpendicular to this centerline but I don't know an efficient way to do this. Can anybody help me out? Thank you very much. Barthttps://uk.mathworks.com/matlabcentral/profile/authors/2251067-barttag:uk.mathworks.com,2005:Question/4358382018-12-14T20:59:20Z2018-12-15T00:54:49ZAdd dead time in SimulinkHi, I am trying to control an H bridge cell. So in order to avoid two swithes turn ON at the same time, I need to add the dead time. I would expect a similar waveform as below. Does anyone konw how to achieve this in Simulink? Thank you so much!
Jiaxiu Donghttps://uk.mathworks.com/matlabcentral/profile/authors/5314450-jiaxiu-dongtag:uk.mathworks.com,2005:Question/4357982018-12-14T17:07:48Z2018-12-15T00:46:21ZWindowing and extracting data from a plot by selecting a zoneHello Everyone,
Motive behind this question is it possible to have a movable window in a figure Where the user moves the window and acquires the desired range of data from a figure?
2) I have tried ginput (by defining 2 points) it does acquire the range of data selected by the user, but the issue in my case is i do not know how many cycles of data is acquired everytime. So would not know how many times do i have to loop ginput for the user to select new range of data everytime.
3)In the Code you would find Variable "Angle" which i haven't used anywhere reason being I want to plot Torque agnist a random x-axis. Select my zone/range have that selected range of torque data compared orginal Torque Data (To know the size of the extracted file) angle data here has the same size as Torque so Now the selected range of torque and its corresponding "Angle" could be written out into a excel file making in (nx2) Matrix.
Any Help would be appreciated. Also copying my code below and have attached a picture which explain what windowing i am talking about.
[filename,pathname] = uigetfile('*.xlsx');
fullfilename = fullfile(pathname,filename);
A = xlsread(fullfilename);
Torque = movmean(A(:,1 ),50);
Angle = movmean(A(:,2),50);
h = plot(Torque);
saveas(h,'All_Data.fig');
% hold on
%pts = ginput(2) ;
h = hgload('All_Data.fig');
get(h)
ch = get(h,'Children');
l = get(ch,'Children');
y = get(l,'ydata')
Anand Gudlurhttps://uk.mathworks.com/matlabcentral/profile/authors/8678603-anand-gudlurtag:uk.mathworks.com,2005:Question/4020802018-05-23T04:50:05Z2018-12-15T00:37:29ZHow to find the neighbors of each element in a matrixHi,
how I can find the neighbors of each element in a given matrix? Does such a method exist in Matlab?
Here is an example :
A=[3 4 8 6;
1 6 9 0;
2 5 7 1]
The neighbors of A(1,1) are {1, 4, 6}; The neighbors of A(1,2) are {3, 1, 6, 8, 9}; The neighbors of A(2, 1) are {3, 2, 4, 6, 5}; The neighbors of A(2, 2) are {3, 1, 2, 4, 5, 8, 9, 7}
Thanks.
Saouhttps://uk.mathworks.com/matlabcentral/profile/authors/7815450-saoutag:uk.mathworks.com,2005:Question/4358302018-12-14T20:32:13Z2018-12-15T00:29:35ZHow does one store all the words from a loop into a variable?
words1 = readTextFile('abc.txt');
words2 = readTextFile('def.txt');
% Access the text file and write contents into an array
wordsA = [words1; words2];
%combining words from both arrays
words3 = readTextFile('ghi.txt');
words4 = readTextFile('jkl.txt');
% Access the text file and write contents into an array
wordsB = [words3; words4];
%combining words from both arrays
Shuffle1 = randperm (length(wordsA));
Shuffle2 = randperm (length(wordsB));
% Create a random array of numbers for the file to be matched to
for i = 1:length(wordsA)
PositionA = Shuffle1 (i); % Use number from the random array
% wordsA (PositionA); % Assign random position to words in text file
RandomWordsA = wordsA(PositionA); %Assign the obtained list to a varible to be displayed
disp (RandomWordsA) %display the random word list
end
for j = 1:length(wordsB)
PositionB = Shuffle2 (j); % Use number from the random array
% wordsB (PositionB); % Assign random position to words in text file
RandomWordsB = wordsB(PositionB);
% RandomWordsB = wordsB(PositionB); %Assign the obtained list to a varible to be displayed
disp (RandomWordsB) %display the random word list
end
RandomWords = [RandomWordsA; RandomWordsB]; %combining words from both arrays
disp (RandomWords) %display the random word lists
Note: the text files all contain 6 words each, the problem is that RandomWordsA and RandomWordsB only have 1 word at the end, which does not allow me to obtain what I need to, which is this, a 12x2 array:
>> a l
>> b m
>> c n
>> d o
>> e p
>> f q
>> g r
>> h s
>> i t
>> j u
>> k vLvny Mhnhttps://uk.mathworks.com/matlabcentral/profile/authors/14369521-lvny-mhntag:uk.mathworks.com,2005:Question/4356792018-12-14T04:54:49Z2018-12-15T00:29:30ZHow can I identify a video frame with scene change using histogram or any other way?I want to seperate only those frames of a video that have scene change information Asma Sajjadhttps://uk.mathworks.com/matlabcentral/profile/authors/13671874-asma-sajjadtag:uk.mathworks.com,2005:Question/4358432018-12-14T21:57:04Z2018-12-15T00:27:07ZCalculate Distance from GPS coordinatesI have 2 columns in a spreadsheet representing the latitude and longitude.
How can I calculate the distance for between the the gps coordinates (eg distance between row 1 and row 2) using the formula
d=ACOS(cos(RADIANS(90-Lat1))*cos(RADIANS(90-Lat2))+sin(RADIANS(90-Lat1))* sin(RADIANS(90-Lat2))*cos(RADIANS(Lon1-Lon2)))* 3958.76
Latitude Longitude
33.47914 -88.7943
33.47914 -88.7943
33.47915 -88.7943
33.47917 -88.7943
jehttps://uk.mathworks.com/matlabcentral/profile/authors/536588-jetag:uk.mathworks.com,2005:Question/2772062016-04-05T07:00:30Z2018-12-15T00:24:00ZSimulink tutorials/ examples for ZynqHello,
I have searched the internet and don't find sufficient examples of simulink for zynq (VHDL code generation). Kindly give me some tutorials/ examples from where I can learn this. I need a supporting document which explains interfacing matlab with vivado as well as I encountering some errors while doing this.sunayana chakradharhttps://uk.mathworks.com/matlabcentral/profile/authors/7970922-sunayana-chakradhartag:uk.mathworks.com,2005:Question/4358362018-12-14T20:56:13Z2018-12-15T00:23:05ZParticle Velocity. Trying to solve for v0 with loops/conditional statementsDisclamier: I am really bad at Matlab. Please go easy on me :)
Problem: I am given a final distance (8.9m), and I want to solve for initial velocity
Approach: I want to use loops/conditionals to solve for the problem. I know it's not the most elegant approach, but this problem is driving me crazy. I would like to increment velocity during each while loop, then check the final value of distance against my given distance (8.9m). If my distance from the while loop is too low, then I would like to increment v0 by 0.01, and run the loop again. When the distance from the while loop equals my given distance, then I have my v0.
I have a good working while loop to figure out the distance from a given v0; however, I am having a hard time incrementing v0 in a way that doesn't put my computer in an infinite loop or returns poor results.
Here's my code:
% Prepare Workspace
clear; % Clears variables from the workspace
clc; % Clears the command window
clf; % Clears current figure window
% Define variables and constraints
g=9.81; %gravity
m=80; % mass
Cd= 0.72; %coefficent of drag
A = 0.5; % cross-sectional area
theta=pi/8; %22.5 deg
v=11.1; %inital velocity
dt=0.0001; %change in time / time step
% Control Jump 1 Data
rho1=0.94; %kg/m^3
D1=.5*Cd*rho1*A;
x1=zeros(1,10000); %x axis index Jump 1
y1=zeros(1,10000); %y axis index Jump 1
t1=zeros(1,10000); %time index Jump 1
xdot=v*cos(theta); % problem description
ydot=v*sin(theta); % problem description
%While loop Control Jump 1 rho 0.94
i=1;
L1=0;
if L1<8.9
v=v+0.01;
x1=zeros(1,10000); %x axis index Jump 1
y1=zeros(1,10000); %y axis index Jump 1
t1=zeros(1,10000); %time index Jump 1
while min(y1)>-0.001
ax1= -(D1/m)*(xdot^2+ydot^2)^0.5*xdot;
ay1= -g-(D1/m)*(xdot^2+ydot^2)^0.5*ydot;
xdot=xdot+ax1*dt;
ydot=ydot+ay1*dt;
x1(i+1)=x1(i)+xdot*dt+.5*ax1*dt^2;
y1(i+1)=y1(i)+ydot*dt+.5*ay1*dt^2;
t1(i+1)=t1(i)+dt;
i=i+1;
end
L1=max(x1); %Length of Jump 1
T1=max(t1); %Time of Jump 1
Y1=max(y1); %Vertical Height of Jump 1
i=1;
end
Thanks for any help!!threex5x7https://uk.mathworks.com/matlabcentral/profile/authors/9471108-threex5x7tag:uk.mathworks.com,2005:Question/4358522018-12-15T00:19:54Z2018-12-15T00:19:54ZNeural Network Checkpoint FrequencyI am training a U-net for image segmentation and I noticed that it seems MATLAB does not allow you to specify the number of iterations per epoch in the training options, and instead defines an epoch as a single run through all the training images. I am using a very large number of images, so that the network runs through around 25,000 iterations per epoch and I would like to be able to test checkpoint networks more frequently than this.
Is there any way to save checkpoint networks more frequently than once per epoch, or to specify iterations per epoch?Jordan Hourihttps://uk.mathworks.com/matlabcentral/profile/authors/13899080-jordan-houritag:uk.mathworks.com,2005:Question/4357422018-12-14T11:47:54Z2018-12-15T00:07:51ZUsing HDL coder for Matlab Function block of SimulinkHello,
On the big picture, I am trying to implement a filter with around 150-200 taps but my filter has some special features thus I don't want to use Simulink's HDL optimized FIR filter. To do this I've written a code that puts simple Simulink blocks into a subsystem, however since a Simulink canvas has finite size and the amount of blocks I can use are naturally limited by the Simulink itself, when there are more taps to the filter (say 600 taps) it gives an error. Also yes, I did as much modularization as I could by gathering constantly used blocks within subsystems as well.
Since I have this problem I thought using Matlab Function block of Simulink would be a better approach. But creating a delay line is a bit problematic for huge amounts of delay. I am trying to use for loop for signal pipelining in the delay line but it either doesn't work as intended, i.e. it doesn't delay the signal right amount, or I am forced to write all the signal pipeline with my hand but then this makes filters with huge number of taps not so practical.
Is there a better tutorial about using HDL coder through Matlab for example? That shows how to do bigger delay lines faster and more modular using loops.Tunç Arslanhttps://uk.mathworks.com/matlabcentral/profile/authors/7440000-tunc-arslantag:uk.mathworks.com,2005:Question/4357632018-10-24T04:00:00Z2018-12-14T23:49:35ZWhy does mex sometimes change its supported compilers from release to release?Are there any technical reasons behind the change from supported compilers? For example, from releases R2017b to R2018a, the supported compiler changed from gcc 4.9 to gcc 6.3 for Linux platforms. Can we still use gcc 4.9 in releases R2018a or newer?
MathWorks Support Teamhttps://uk.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:uk.mathworks.com,2005:Question/4358182018-12-14T18:50:48Z2018-12-14T23:46:40ZHow to plot Central/Non-central chi square pdf?I have 1000 samples of energy. I want to plot central and non-central chi square pdf. I checked the Matlab documentation, I don't understand, how to calculate/choose values of degree of freedom and delta. Can anyone help?Abdullah Masoodhttps://uk.mathworks.com/matlabcentral/profile/authors/8875499-abdullah-masoodtag:uk.mathworks.com,2005:Question/4352502018-12-11T23:50:48Z2018-12-14T23:41:17Zcannot get YOLO algorithm example to work dont have openCV libraryWhere did you find an openCV library to run the YOLO Algorithm example or did you generate your own library? Since Matlab cannot provide the library that is needed. I have every other library installed on my computer but cannot find the correct library. I have downloaded the openCV library off SourgeForce but not a single library I downloaded worked with the example. Any suggestions would be greatly appreciated.Caleb Lindhorsthttps://uk.mathworks.com/matlabcentral/profile/authors/4045067-caleb-lindhorsttag:uk.mathworks.com,2005:Question/4358042018-12-14T17:37:32Z2018-12-14T23:38:25ZHow to send commands to gps via usb and defined as a serial port?Hello,
I am reading data from the BU-353S4 gps unit and have defined the connection as a serial/com. It receives commands in the NMEA system in order to define what outputs to give. This commands have the following format:
Enable WAAS/EGNOS - $PSRF151,01*0F
Disable WAAS/EGNOS - $PSRF151,00*0E
Enable GGA Output 1sec - $PSRF103,0,0,1,1*25
Disable GGA Output - $PSRF103,0,0,0,1*24
Enable GLL Output 1sec - $PSRF103,1,0,1,1*24
Disable GLL Output - $PSRF103,1,0,0,1*25
Enable GSA Output 5sec - $PSRF103,2,0,5,1*23
Disable GSA Output - $PSRF103,2,0,0,1*26
Enable GSV Output 10sec - $PSRF103,3,0,10,1*16
Disable GSV Output - $PSRF103,3,0,0,1*27
Enable RMC Output 1sec - $PSRF103,4,0,1,1*21
Disable RMC Output - $PSRF103,4,0,0,1*20
Enable VTG Output 1sec - $PSRF103,5,0,1,1*20
Disable VTG Output - $PSRF103,5,0,0,1*21
Enable ZDA Output 1sec - $PSRF103,8,0,1,1*2D
Disable ZDA Output - $PSRF103,8,0,0,1*2C
The commands start with the $ sign. How can I send any of these to the gps through MATLAB?Philip Nahmiashttps://uk.mathworks.com/matlabcentral/profile/authors/9449116-philip-nahmiastag:uk.mathworks.com,2005:Question/4061772018-06-18T14:54:52Z2018-12-14T23:37:54Zsevere problems opening files with Matlab 2018aWhen I try to open a file in Matlab 2018a, I get the following error:
>> open check_adc_vs_fir_samples.m
Error using open (line 146)
PATTERN must be a string scalar or character vector.
Cannot open file using dialog box either, I get same error message popping up as error dialog.
I'm an expert user of Matlab over 15 years, this is the first version of Matlab that I've seen this error. Normally I'm able to debug but can't resolve this on my own. Need Mathworks support.Jason Juryhttps://uk.mathworks.com/matlabcentral/profile/authors/1415619-jason-jurytag:uk.mathworks.com,2005:Question/4356392018-12-13T20:43:02Z2018-12-14T23:30:12ZApplying 3D Rotation MatrixI have 2 sets of 3D axes in Matlab. I have a list of points in the first set of 3D axes that I want to apply a rotation matrix to in order to convert them to the same location in the second set of axes. I am a bit rusty with applying rotation matrices, any help is appreciated. Student123https://uk.mathworks.com/matlabcentral/profile/authors/14074492-student123tag:uk.mathworks.com,2005:Question/4358132018-12-14T18:34:46Z2018-12-14T23:28:01ZConvert Torque Mechanical unit from pu to Si Hello,
I have model of DFIG in pu, the Simulink output of the block give Torque Mechanical unit in pu, I need to make it in SI unit in scope, how doing that.. Thanks inadvance to your helpmuhammad farttooshttps://uk.mathworks.com/matlabcentral/profile/authors/4279675-muhammad-farttoostag:uk.mathworks.com,2005:Question/4358492018-12-14T23:08:14Z2018-12-14T23:27:35ZHow to calculate multiplying two matrices using (for) and (if) loops together ???How to calculate multiplying two matrices provided that the number of line elements in the first matrix equals the number of column elements in the second matrix (using the loop (for) and (if) together) thank youhcourah samehttps://uk.mathworks.com/matlabcentral/profile/authors/14369858-hcourah-sametag:uk.mathworks.com,2005:Question/4358482018-12-14T22:54:14Z2018-12-14T23:17:43ZReplace several occurrence of one string with multiple different strings using regexprep without a for loopHow can I replace several occurrence of one string with multiple different strings?
I would like to use regexprep without using a for loop.
For example, in this string, I would like to replace the first "XXX" with "ALPHA" and the second "XXX" with "BETA"
string = '2*sin(XXX)+XXX'
I would try these (which none obviously works)
string = regexprep(string,'XXX' , {'ALPHA','BETA'})
string = regexprep(string,{'XXX','XXX'}, {'ALPHA','BETA'})Alborz Sakhaeihttps://uk.mathworks.com/matlabcentral/profile/authors/8540779-alborz-sakhaeitag:uk.mathworks.com,2005:Question/4358262018-12-14T19:47:42Z2018-12-14T23:16:14ZCan i use Simulink to cosimulate my implemented design?Hi, I want to use Simulink to co-simulate in Modelsim my VHDL design, but I want it to be implemented.
I have used HDL cosimulation , and it works but I need the design to be implemented. Also, I have used FIL to test the design in hardware, but I wonder if I can use a block like I used to perform FPGA in the loop but using Modelsim.
Thanks a lot for your anwers.Juan José Montes Salinerohttps://uk.mathworks.com/matlabcentral/profile/authors/7938978-juan-jose-montes-salinerotag:uk.mathworks.com,2005:Question/3136312016-11-23T10:30:29Z2018-12-14T22:59:39ZHow to multiply two matrices with nested for loops ?How can I do that with two matrices with any dimensions that can multiply ?
Thank youDenememehttps://uk.mathworks.com/matlabcentral/profile/authors/9249989-denememetag:uk.mathworks.com,2005:Question/4352922018-12-12T07:27:15Z2018-12-14T22:35:35Zmac Matlab 2018b with xcode10 installed still No supported compiler was foundWarning: Xcode is installed, but its license has not been accepted.
Run Xcode and accept its license agreement.
> In make (line 13)
Error: path_to_libsvm/libsvm-3.23/matlab/make.m failed (line 13)
No supported compiler was found. For options, visit https://www.mathworks.com/support/compilers.
I would like to compile some C codes with mex. However, even with brand new matlab 2018b and xcode10(for now) installed on my mac could not compile these files.
Yeah, I know the warning about Xcode license issue and that's strange since I DID aceept these license by typing
sudo xcodebuild -license
in command line and accepting it.
So anyone with same experience or some suggestions ? I would be very appreciated if you do ! 0.0
xie linghttps://uk.mathworks.com/matlabcentral/profile/authors/9031393-xie-lingtag:uk.mathworks.com,2005:Question/4353092018-12-12T09:05:33Z2018-12-14T22:33:03ZCan Matlab web app server access the hardware of a server?Hi,
I would like to know if it is possible to access Hardware, for an example a COM port, from a matlab web app.
My idea would be to have web based data logging app, that can be accessed anywhere from within the local network.
Best regards
FelixFelix Ritzkowskyhttps://uk.mathworks.com/matlabcentral/profile/authors/4253806-felix-ritzkowskytag:uk.mathworks.com,2005:Question/4357742018-12-14T14:36:53Z2018-12-14T22:27:07ZHow to simulate bit stuffing on a 20860×1 matrix of binary data?Hello everyone,
i have a matrix of binary data of size 20860×1. (20860 rows and 1 column), and i would like to perform bit stuffing on it, which means to insert a zero after each six consecutive ones
so if i have a sequence like this in my matrix: 0 0 0 1 1 1 1 1 1 1 0
then after the bit stuffing it will be like this: 0 0 0 1 1 1 1 1 1 0 1 0
i tried doing this using two for loops but it didn't work properly
let the data matrix be called: collect, and let it be a matrix of random binary data
collect=randi([1 0],20860,1);
Rania Fahmyhttps://uk.mathworks.com/matlabcentral/profile/authors/10680404-rania-fahmytag:uk.mathworks.com,2005:Question/4358452018-12-14T22:14:05Z2018-12-14T22:14:05ZHow can I use pushbuttons in GUI to categorize a "like" or "dislike" of a imageI've been stuck on this problem and can't seem to find the right kind of tutorials online that would point me in the right direction.
My goal is to use a GUI that has two pushbuttons, a "like" and a "dislike" pushbutton.
I add the folder with all the images to my path so when my gui opens, the first image automatically pops up. Then I hit "like" or "dislike", and that information is saved as a logical corresponding to the image title in a structural array.
I've spent several hours working on creating practice GUI's that do other things to understand how everything works together, but I'm feeling in over my head maybe? Does anyone have any idea's, hints, or resources that they have in mind? Rachel Larsenhttps://uk.mathworks.com/matlabcentral/profile/authors/13575761-rachel-larsentag:uk.mathworks.com,2005:Question/4358272018-12-14T20:01:47Z2018-12-14T22:06:37ZGlobal variables. How to write global variables?I need to create scripts and functions in which data is exchanged only through global variables. I need to create a script with vector from 2*pi to -2*pi with step -0.1; and this script should calculate this function:
and I have created script and 2 functions.
Script:
The answer is good but I need to make global variables and I have no clue how to overwrite this script ant functions. Any ideas?dovis838https://uk.mathworks.com/matlabcentral/profile/authors/14369330-dovis838tag:uk.mathworks.com,2005:Question/4358282018-12-14T20:19:17Z2018-12-14T22:05:10ZMake x-axis display multiple times the interval of 0 to 360 degreesSo, I am trying to make a figure, which displays a periodic signal, but instead of time, I want x-axis to display degrees.
The thing is that I cannot figure out a way for the x-axis to display multiple times the interval of 0 to 360 degrees. I only can create the following
mod(x_axis,360) obviously doesn't work
Any ideas?
EDIT
Just to be clear, I want to display something like that:
Theo Paphttps://uk.mathworks.com/matlabcentral/profile/authors/10120414-theo-pap