https://kr.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2018-12-10T08:33:30Ztag:kr.mathworks.com,2005:Question/4348622018-12-10T08:33:30Z2018-12-10T08:33:30Zhow to implement the Euclidean distance between subjects to calculate the distance between the test image and all the trains images..... thanks in advance hi guys ,
if any one can help me please , i'm dealing with dataset
i have 100 class (1 pic each class ) testing
and 100 class (2 pic each class ) trainning
at the end after i used PCA (100 featureVectors)
i want to use Euclidean Distance between (100x1 cell and 100x2 cell) ,
testing table
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
1x100 double
-------------------------------------------
trainning table
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
1x100 double 1x100 double
Noor Abbashttps://kr.mathworks.com/matlabcentral/profile/authors/13405574-noor-abbastag:kr.mathworks.com,2005:Question/4348482018-12-10T07:15:59Z2018-12-10T08:33:18ZSyntax of aspect calculation equationGood time of a day. I am at deadlock. I have to calculate Aspect for my data, but the values are 180 times higher(it should be in range 0-360). this is an original equation of Aspect:
A0 = -90[1 -sign( q)](1 - |sign( p)|) + 180[1 + sign( p)] - 180sign( p)arccos[ - q/( p^2 + q^2)^1/2]/pi
And this is how i tried to implement it in MATLAB:
Aspect = -90.*(1-sign(zy)).*(1-abs(sign(zx)))+180.*(1+sign(zx))-180.*(sign(zx)).*acosd((-zy)./((zx.^2+zy.^2).^0.5)/pi);
I will be very grateful if someone help to solve this syntax problem. Thank you in advance.Anton Popovhttps://kr.mathworks.com/matlabcentral/profile/authors/14336257-anton-popovtag:kr.mathworks.com,2005:Question/4348602018-12-10T08:14:55Z2018-12-10T08:33:15ZVERY URGENT::::: My code is giving me this error: Index in position 2 is invalid. Array indices must be positive integers or logical values. Can you please resolve this for me? It is very urgent and due in two days!!!%####********Analytical Solutions *********#####
%#### This is simply plugging in the results from problem 1
%### Constants
sigmaa=0.005;
D=0.6;
L = (D/sigmaa)^0.5;
T=45;
So=10^8;
%### Slab Problem
x=linspace(0,45,10000);
U = (D/(2*L)-1/4)/(D/(2*L)+1/4);
C = (-So*T/sigmaa)*(T/4+D)/(-(D/(2*L)-1/4)^2/(D/(2*L)+1/4)*exp(-T/L)+(D/(2*L)+1/4)*exp(T/L));
A = U*C;
flux_slab=[];
for i = 1:x
ans1 = A*exp(-i/L)+C*exp(i/L)+(So*i^2)/sigmaa;
flux_slab = ans1;
end
%### Cylindrical Problem
x2=linspace(0,45/2,10000);
flux_cyl=[];
for i = 1:x2
ans1 = -So/(2*sigmaa*(0.5*besseli(0,T/(2*L))+(D/L)*besseli(1,T/(2*L))))*besseli(0,i/L)+(So/sigmaa);
flux_cyl = ans1;
end
%#### Sphere Problem
flux_sph=[];
for i = 1:x2
flux_sph = (-So*sinh(i/L)/(i*4*sigmaa*(sinh(T/(2*L))/(2*T)+(2*D/L)*(T/2*cosh(T/(2*L))-L*sinh(T/(2*L)))/(T^2))))+So/sigmaa;
end
flux_comp_slab_10 = Diffusion('slab', 45, 10, 0.005, 0.6, 10^8);
flux_comp_slab_100 = Diffusion('slab', 45, 100, 0.005, 0.6, 10^8);
flux_comp_slab_1000 = Diffusion('slab', 45, 1000, 0.005, 0.6, 10^8);
flux_comp_slab_10000 = Diffusion('slab', 45, 10000, 0.005, 0.6, 10^8);
flux_comp_cyl_10 = Diffusion('cylinder', 45/2, 10, 0.005, 0.6, 10^8);
flux_comp_cyl_100 = Diffusion('cylinder', 45/2, 100, 0.005, 0.6, 10^8);
flux_comp_cyl_1000 = Diffusion('cylinder', 45/2, 1000, 0.005, 0.6, 10^8);
flux_comp_cyl_10000 = Diffusion('cylinder', 45/2, 10000, 0.005, 0.6, 10^8);
flux_comp_sph_10 = Diffusion('sphere', 45/2, 10, 0.005, 0.6, 10^8);
flux_comp_sph_100 = Diffusion('sphere', 45/2, 100, 0.005, 0.6, 10^8);
flux_comp_sph_1000 = Diffusion('sphere', 45/2, 1000, 0.005, 0.6, 10^8);
flux_comp_sph_10000 = Diffusion('sphere', 45/2, 10000, 0.005, 0.6, 10^8);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% PLOTTING OPTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
x3=linspace(0,45/2,10);
x4=linspace(0,45/2,100);
x5=linspace(0,45/2,1000);
x6=linspace(0,45/2,10000);
x7=linspace(0,45/2,100000);
figure(1);
plot(x, flux_slab);
hold on
plot(x3*2, flux_comp_slab_10);
plot(x4*2, flux_comp_slab_100);
plot(x5*2, flux_comp_slab_1000);
plot(x6*2, flux_comp_slab_10000);
hold off
figure(2);
plot(x, flux_cyl);
hold on
plot(x3*2, flux_comp_cyl_10);
plot(x4*2, flux_comp_cyl_100);
plot(x5*2, flux_comp_cyl_1000);
plot(x6*2, flux_comp_cyl_10000);
hold off
figure(2);
plot(x, flux_sph);
hold on
plot(x3*2, flux_comp_sph_10);
plot(x4*2, flux_comp_sph_100);
plot(x5*2, flux_comp_sph_1000);
plot(x6*2, flux_comp_sph_10000);
hold off
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% FUNCTION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DEFINITIONS
function A = SOR(x, So)
S = zeros(length(x),1); % BLANK MATRIX
for i = 1:(length(S)-1)
S(i)=So*(x(i)^2);
end
A=S;
return
end
function B = SORSC(x, So)
S = zeros(length(x),1); % BLANK MATRIX
for i = 1:(length(s)-1)
S(i)=So;
end
B=S;
return
end
function C = Diffusion(geometry, Size, N, SigmaA, D, So)
x = linspace(0,Size,N) ; % Set the size to iterate and number of nodes
delta = (x(2)-x(1)); % Distance between nodes
L = zeros(length(x), length(x)); % Start with a blank matrix
% GEOMETRY TYPE
if geometry=='slab' % Depending on geometry make tridiagonal terms
S = SOR(x, So) / D; % Recieve source term from source def
for i = 1:(length(x)-1) % Iterate over tri diagonal
L(i,i) = 2/(delta^2)+SigmaA/D; % Diagonal Terms
L(i,i+1) = -1/(delta^2); % Above diagonal term
L(i,i-1) = -1/(delta^2); % Below diagonal term
end
% Set boundary conditions at ends (Vacuum conditions)
L(0,0) = 0.5*(0.5-D/delta);
L(0,1) = D/(2*delta);
L(length(x)-1,length(x)-1) = 0.5*(0.5-D/delta);
L(length(x)-1, length(x)-2) = D/(2*delta);
elseif geometry=='cylinder'
S = SORSC(x, So) / D ; % Recieve source term from source def
for i = 1:(length(x)-1) % Iterate over tri diagonal
L(i,i) = (x(i+1)/(x(i)*(delta^2))+1/(delta^2)+SigmaA/D); % Diagonal Terms
L(i,i+1) = -x(i+1)/(x(i)*delta^2); % Above diagonal term
L(i,i-1) = -1/(delta^2); % Below diagonal term
end
% Set boundary conditions at ends (Vacuum conditions 2/ symmetry)
L(0,0) = -1/delta;
L(0,1) = 1/delta;
L(length(x)-1,length(x)-1) = D/(2*delta);
L(length(x)-1, length(x)-2) = 0.5*(0.5-D/delta);
elseif geometry=='sphere'
S = SORSC(x, So) / D; % Recieve source term from source def
for i = 1:(len(x)-1) % Iterate over tri diagonal
% Diagonal Terms
L(i,i) = (x(i+1)^2)/((x(i)^2)*(delta^2)) + 1/(delta^2) + SigmaA/D;
L(i,i+1) = -x(i+1)^2 / (x(i)^2 * delta^2); % Above diagonal term
L(i,i-1) = -1/(delta^2); % Below diagonal term
end
% Set boundary conditions at ends (Vacuum conditions w/ symmetry)
L(0,0) = -1/delta;
L(0,1) = 1/delta;
L(length(x)-1,length(x)-1) = D/(2*delta);
L(length(x)-1, length(x)-2) = 0.5*(0.5-D/delta);
else
sprintf("Not a valid geometry option");
end
flux = linsolve(L,S);
C=flux;
return
end
Sanchit Sharmahttps://kr.mathworks.com/matlabcentral/profile/authors/13394492-sanchit-sharmatag:kr.mathworks.com,2005:Question/796342013-06-20T01:53:44Z2018-12-10T08:26:23ZSplitting an axis into a linear and log scaleHi,
I'm interested in splitting the x-axis of a plot into a linear section and a log section. For example, I want to plot -1 to 20 on a linear scale then switch to a log scale for 20 to 4500 on the same axis. I've looked into functions like semilog and plotxx, and log log, but I can't find anything that allows me to split the axis into two separate scales.
Thanks a lot,
CharlesSenaasahttps://kr.mathworks.com/matlabcentral/profile/authors/4211999-senaasatag:kr.mathworks.com,2005:Question/4348582018-12-10T08:14:04Z2018-12-10T08:24:57ZInput to num2str must be numeric.clc;
disp('a')
syms H zeta
omega = 1;
solve(H == 1/sqrt((1-omega^2)^2 + (2*zeta*omega)^2),zeta);
H = [10 5 2.66 1 0.5];
for i=1:5
zetas(i) = 1/(2*H(i));
end
disp([' Damping Factor for system 1 = ' num2str(zetas(1)) ''])
disp([' Damping Factor for system 2 = ' num2str(zetas(2)) ''])
disp([' Damping Factor for system 3 = ' num2str(zetas(3)) ''])
disp([' Damping Factor for system 4 = ' num2str(zetas(4)) ''])
disp([' Damping Factor for system 5 = ' num2str(zetas(5)) ''])
disp('----------------x---------------')
disp('b')
clear omega
syms omega
for i=1:3
omegas = solve(1 == 1/sqrt((1-omega^2)^2 + (2*zetas(i)*omega)^2));
omega_star(i) = max(omegas);
end
disp([' Omeaga* for system 1 = ' num2str(omega_star(1)) ''])
disp([' Omeaga* for system 2 = ' num2str(omega_star(2)) ''])
disp([' Omeaga* for system 3 = ' num2str(omega_star(3)) ''])
Getiing error for num2str(omega_star).... Input to num2str must be numeric.
It works for the disp([' Damping Factor for system 1 = ' num2str(zetas(1)) ''])Abhinay Tadwalkarhttps://kr.mathworks.com/matlabcentral/profile/authors/10832164-abhinay-tadwalkartag:kr.mathworks.com,2005:Question/4348612018-12-10T08:17:15Z2018-12-10T08:17:15Zxlswrite() misfunction with Officehello.
i am trying to write using xlswrite().
a new company Office version has been insatlled: 1811 (Build 1109.20079).
the function fails and I repeatedly get a comment that the file is already opened by another program.
any help will be greatly appreciated!
thanks!!
mat
mathttps://kr.mathworks.com/matlabcentral/profile/authors/3626535-mattag:kr.mathworks.com,2005:Question/4348592018-12-10T08:14:54Z2018-12-10T08:14:54Zfor train auto encoder I want dimension reduction by using three autoencoder.
the size of my data is 400*144; mean 400 sample whith 144 feature.
after run first autoencoder by hiden size 72.
What is the input for the next Autoencoder?zahra khalilparvarhttps://kr.mathworks.com/matlabcentral/profile/authors/8582666-zahra-khalilparvartag:kr.mathworks.com,2005:Question/4348572018-12-10T08:12:59Z2018-12-10T08:12:59ZConvert Matlab Code to MATLAB System Block in SimulinkHi I need help to convert Matlab Code file to a MATLAB system in Simulink.
For an example the coded function below have been made in the terms of code file. However, when I try to recall the function from MATLAB System, it says it's not a system object.
function [dCadt,dTdt] = reactor1(Ca, T)
Ea=4800;
k0=1e12;
dH=5000;
U=15;
rhocp=0.2;
R=1.7;
V=70;
F=6000;
Caf=1.32;
Tf=40;
A=11;
Tj=80.9;
dCadt=((F/V)*(Caf-Ca))-(k0*Ca*exp(-Ea/(R*(T+460))));
dTdt=((F/V)*(Tf-T))-(dH)/(rhocp)*(k0*Ca*exp(-Ea/(R*(T+460)))-(U*A)/(rhocp*V)*(T-Tj));Muhd Azizan Ismailhttps://kr.mathworks.com/matlabcentral/profile/authors/13237805-muhd-azizan-ismailtag:kr.mathworks.com,2005:Question/4348542018-12-10T08:04:09Z2018-12-10T08:12:39ZHow do make matlab workspace to show variable value or size of the array.usuall the varible's value is displayed. but when i tried to re arrange the workspace, varibale got vanished
Gowshigan Selvarasahttps://kr.mathworks.com/matlabcentral/profile/authors/13189191-gowshigan-selvarasatag:kr.mathworks.com,2005:Question/3524282017-08-11T11:44:41Z2018-12-10T08:11:48ZHow do you reconstruct a test image from eigenfaces generated from Matlab pca functionHi All,
I have been trying to reconstruct a test image from the eigenvectors generated from the pca function, however the reconstructed image is different from the test image (see figure). The test image is simply one of the images used in the training set. I also tried obtaining the eigenvectors using the cov and eig functions but I still end up with the same problem. I need to use the pca function and will appreciate any help on how to obtain the eigenvectors from its output.
Find the code below. I have also attached a zip file containing the matlab code and images I used.
Thanks in anticipation.
M = 10; % number of images
for n=1:M
im = imread(strcat(num2str(n),'.jpg')); %read image
im = im2double(rgb2gray(im)); % convert image to gray scale and then to double precision
[r,c] = size(im); % get number of rows and columns in image
I(:,n) = im(:); % convert image to vector and store as column in matrix I
end
% calculate mean image
I_mean = mean(I,2);
% subtract mean image from the set of images
I_shifted = I-repmat(I_mean,1,M);
%perform PCA. Matrix I was used as input instead of I_shifted because Matlab documentation states that pca function centers the data
[coeff,score,latent,~,explained,mu] = pca(I);
%calculate eigenfaces
eigFaces = I_shifted*coeff;
% put eigenface in array and display
ef = [];
for n = 1:M
temp = reshape(eigFaces(:,n),r,c);
temp = histeq(temp,255);
ef = [ef temp];
end
figure;
imshow(ef,'Initialmagnification','fit');
title('Eigenfaces');
% load one of the training images to test reconstruction
im = im2double(rgb2gray(imread('1.jpg'))); % convert to gray and then to double
I_test = im(:); % convert image to vector
I_test = I_test-I_mean; % subtract mean images
%calculate weights of test image
I_test_weights = zeros(M,1);
for jj = 1:M
I_test_weights(jj,1) = dot(I_test,eigFaces(:,jj));
end
% reconstruct test image
I_recon = I_mean + eigFaces*I_test_weights;
%reshape reconstructed test image
I_recon = reshape(I_recon, r,c);
%display original and reconstructed test image
figure
subplot(1,2,1);
imshow(im);
title('Original test image');
subplot(1,2,2)
imshow(I_recon);
title('Reconstructed test image');
<</matlabcentral/answers/uploaded_files/85316/reconstructed.PNG>>
Iktechhttps://kr.mathworks.com/matlabcentral/profile/authors/6587754-iktechtag:kr.mathworks.com,2005:Question/4348562018-12-10T08:10:47Z2018-12-10T08:10:47ZI am having this error "Index in position 2 is invalid. Array indices must be positive integers or logical values." in my file. Can you please help me in resolving this. It is very urgent? I am very new to matlab and am having some syntax errors. The code is due for submission in a few days. I will be very grateful for solution. . . .
Sanchit Sharmahttps://kr.mathworks.com/matlabcentral/profile/authors/13394492-sanchit-sharmatag:kr.mathworks.com,2005:Question/4348552018-12-10T08:10:02Z2018-12-10T08:10:02ZHow to fix differences in WAVE file header between 'wavwrite' and 'audiowrite'I am working with a numerical model implemented in FORTRAN95 which reads in 800kHz .wav files (due to historical reasons). In the past I used MATLABs 'wavwrite' function which provided me with files I could read. In FORTRAN I read the header according to the Canonical WAVE file format (e.g. http://soundfile.sapp.org/doc/WaveFormat/)
I get the following output for the file that works:
------------------------
RIFF
1600036
WAVE
fmt
16
3
1
800000
3200000
4
32
data
1600000
------------------------
generated by the following MATLAB code:
wavwrite(sig,wav_fs,32,[wav_filename]);
and for the file that doesn't work in the model:
------------------------
RIFF
3200072
WAVE
fmt
16
3
1
800000
3200000
4
32
fact
4
------------------------
generated by the following MATLAB code (R2018a)
audiowrite(fname,sig,fs,'BitsPerSample',32)
Am I missing something - an extra option? I can't find information about what 'fact' means in that position of the WAVE file header. Before I now start recoding the FORTRAN code, is there an easy way out?
B Ehttps://kr.mathworks.com/matlabcentral/profile/authors/2275880-b-etag:kr.mathworks.com,2005:Question/4348512018-12-10T07:38:48Z2018-12-10T08:09:36ZMatlab floating point problemHello. I am using Matlab R2007b. I have a floating point problem in it. I am using x=rotx(45*pi/180)*[1 2 3]' and its value is x =[1.0000; 3.5355; 0.7071]. And i am doing reverse rotation of x which is y=rotx(-45*pi/180)*x. And i am doing y==[1; 2; 3]. Logically it is showing 1 1 0. I want all 1's when y==[1; 2; 3]. Can any one help with this problem.kartheek rajhttps://kr.mathworks.com/matlabcentral/profile/authors/12835249-kartheek-rajtag:kr.mathworks.com,2005:Question/4348342018-12-10T04:26:16Z2018-12-10T07:55:39ZI'm tryng to calculate some number and matrix with my robotics project and facing this problem when run the code. Can anyone explain for me, i'm just a newbie. Thank you very much. The error is after the code.
clc
syms q1 q2 q3 dq1 dq2 dq3 a1 a2 m1 m2 m3 t g f
assume(a1, 'real');assume(a1>0);
assume(a2,'real');assume(a2>0);
assume(q3,'real');
assume(dq3,'real');
assume(q1,'real');
assume(q2,'real');
assume(dq1,'real');
assume(dq2,'real');
assume(t,'real');assume(t>0);
assume(f,'real');
q = [q1;q2;q3]; %vecto cac toa do suy rong
dq = [dq1;dq2;dq3]; %vecto cac dao ham toa do suy rong
%Nhap cac ma tran D-H
A_01=[ cos(q1) -sin(q1) 0 a1*cos(q1);sin(q1) cos(q1) 0 a1*sin(q1);0 0 1 0;0 0 0 1;];
A_12=[cos(q2) -sin(q2) 0 a2*cos(q2);sin(q2) cos(q2) 0 a2*sin(q2);0 0 1 0;0 0 0 1;];
A_23=[1 0 0 0;0 -1 0 0;0 0 -1 -q3;0 0 0 1;];
% Tính các ma tran cosin chi phuong
R_01=A_01(1:3,1:3);
A_03=A_01*A_12*A_23;
A_02=simplify(A_01*A_12);disp(A_02); % Sau khi tính toán ta thu gon ket qua ngay bang lenh simplify
R_02=A_02(1:3,1:3);
disp('Ma tran bien doi thuan nhat khau cuoi la');
A_03 = simplify(A_03);
R_03 = A_03(1:3,1:3);
disp(A_03);
%Giai bai toan dong hoc thuan
disp('Giai bai toan dong hoc thuan');
disp('toa do diem cuoi');
rE = A_03(1:3,4); disp(rE);% Vector toa do khâu thao tác
disp('van toc diem cuoi')
v_qE = simplify(jacobian(rE,q)*dq);disp(v_qE); % Tính vector van toc khâu tác dong cuoi
jacobian(rE,q); disp('Jacobi tinh tien'); disp(jacobian(rE,q));
R_0E = A_03(1:3,1:3); disp(R_0E);
diff_R_0E = diff(R_0E,q1)*dq1+diff(R_0E,q2)*dq2; %Tinh dao ham cua R
omega_curveE = diff_R_0E*R_0E.'; %omega song khau cuoi
omega_curveE = simplify(omega_curveE);
disp('Van toc goc khau cuoi:');
omega3 = [omega_curveE(3,2) omega_curveE(1,3) omega_curveE(2,1)]; disp(omega3); %omega
jacobian(omega3,dq); disp('Jacobi quay khau cuoi'); disp(jacobian(omega3,dq));
R_01 = A_01(1:3,1:3); disp(R_01);
diff_R_01 = diff(R_01,q1)*dq1+diff(R_01,q2)*dq2;
omega_curve1 = diff_R_01*R_01.';
omega_curve1 = simplify(omega_curve1);
disp('Van toc goc khau thu nhat');
omega1 = [omega_curve1(3,2) omega_curve1(1,3) omega_curve1(2,1)]; disp(omega1); %omega
jacobian(omega1,dq); disp('Jacobi quay khau thu nhat'); disp(jacobian(omega1,dq));
R_02 = A_02(1:3,1:3); disp(R_02);
diff_R_02 = diff(R_02,q1)*dq1+diff(R_02,q2)*dq2;
omega_curve2 = diff_R_02*R_02.';
omega_curve2 = simplify(omega_curve2);
disp('Van toc goc khau thu hai');
omega2 = [omega_curve2(3,2) omega_curve2(1,3) omega_curve2(2,1)]; disp(omega2); %omega
jacobian(omega2,dq); disp('Jacobi quay khau thu hai'); disp(jacobian(omega2,dq));
%tinh gia toc diem cuoi %chua tinh dc
diff_v_qE = diff(v_qE,q1)*dq1 + diff(v_qE,q2)*dq2;
disp('gia toc diem cuoi la:'); disp(diff_v_qE);
%tinh gia toc goc diem cuoi
%diff_omega = diff(omega,q1)*dq1 + diff(omega,q2)*dq2;
%disp('gia toc goc khau thao tac'); disp(diff_omega);
%khao sat can bang tinh
F_3E = [0 0 f]; % luc gia cong tai diem cuoi so voi he 3
F_0E = F_3E*R_03;
P_01 = [0 0 -m1*g]; %trong luc tac dung len C1
P_02 = [0 0 -m2*g];
P_03 = [0 0 -m3*g];
r_0C1 = [(a1/2)*cos(q1) (a1/2)*sin(q1) 0]; %toa do C1 so voi he 0
r_1C2 = [(a2/2)*cos(q2) (a2/2)*sin(q2) 0];
r_0C2 = r_1C2*R_01;
r_2C3 = [-q3/2 0 0];
r_0C3 = r_2C3*R_02;
J_TE = jacobian(rE,q);
J_TC1= jacobian(r_0C1,q);
J_TC2= jacobian(r_0C2,q);
J_TC3= jacobian(r_0C3,q);
%luc dong co
Tdc = -J_TE.'*F_0E - P1.'*J_TC1 - P2.'*J_TC2 - P3.'*J_TC3;
disp('luc dong co co gia tri la'); disp(Tdc);
F_0_32 = F_0E - P_03; disp('luc tac dung tu khau 2 len khau 3'); disp(F_0_32);
F_0_21 = F_0_32 - P_02; disp('luc tac dung tu khau 1 len khau 2'); disp(F_0_21);
F_0_10 = F_0_21 - P_01; disp('luc tac dung tu khau 0 len khau 1'); disp(F_0_10);
Csym = mupadmex(op,args{1}.s, args{2}.s, varargin{:});
Error in * (line 244)
X = privBinaryOp(A, B, 'symobj::mtimes');
Error in ltmp (line 97)
Tdc = -J_TE.'*F_0E - P1.'*J_TC1 - P2.'*J_TC2 - P3.'*J_TC3;
Anh Tonghttps://kr.mathworks.com/matlabcentral/profile/authors/14335568-anh-tongtag:kr.mathworks.com,2005:Question/4340692018-12-05T18:10:09Z2018-12-10T07:54:54ZProblem with the .mltbx toolbox file in Matlab 2018aI download the Mobile Robotics Simulation Toolbox file but it is impossible for me to install it on my Mac OS computer.
The error message is :
Toolbox cannot be installed. Installation path is not accessible.
I tryed several test and also to create the a folder Mobile Robotics Simulation in the Toolbox folder but it does not want to install it.
Thank for your help.
JChttps://kr.mathworks.com/matlabcentral/profile/authors/2283711-jctag:kr.mathworks.com,2005:Question/4337302018-12-04T11:06:02Z2018-12-10T07:51:57Zaudio compression (shorten an audio file)I want to compress an audio file to make it shorter to put in a game for sound effects. I use the following:
[y,Fs]=wavread('blast.wav');
t1=0;% start time
t2=2;% end time
yNew=y((Fs*t1+1):Fs*t2,1);
wavwrite(yNew,Fs,'soundShort.wav');
The compression is fine and 'soundShort.wav' can play. But command sound(wavread('soundShort.wav')) no longer has any sound, though it's runnable. I wonder what goes wrong.a ahttps://kr.mathworks.com/matlabcentral/profile/authors/11974203-a-atag:kr.mathworks.com,2005:Question/4348522018-12-10T07:41:19Z2018-12-10T07:50:36ZError using sym/sin : Too many input arguments clc;
syms w k c m F0 t
w_n = (k/m)^(1/2);
zeta = c/(2*w_n*m);
A = F0*(k-m*w^2)/((c*w)^2 + (k-m*w^2)^2);
B = F0*c*w/((c*w)^2 + (k-m*w^2)^2);
x = A*cos(w*t) + B*sin(w,t);
xd = jacobian(x,t);
xdd = jacodian(xd,t);
Dynamic_Differential_Equation = m*xdd + c*xd + k*xAbhinay Tadwalkarhttps://kr.mathworks.com/matlabcentral/profile/authors/10832164-abhinay-tadwalkartag:kr.mathworks.com,2005:Question/3098042016-10-30T05:01:09Z2018-12-10T07:50:19ZStrategy for matching multiple templates in an imageI have followed the concept given in the link :- <https://www.youtube.com/watch?v=Q-OzmDen4HU> . With these thing i was able to get a single template match. But I have a problem definition wherein i need to find all the templates in an image. I have gone through a link <http://docs.adaptive-vision.com/current/studio/machine_vision_guide/TemplateMatching.html> which suggests threshold or maxima for getting all the templates.But i was not able to get how to define a threshold or strategy for getting all templates in an image. The following code gives me the best match :-
[rowcc, colcc] = size(cc);
[max_cc, imax] = max(abs(cc(:)));
[ypeak xpeak] = ind2sub(size(cc), imax(1));
peakvalues = cc(xpeak,ypeak);
BestRow = ypeak - (crows-1);
BestCol = xpeak - (ccols-1);
val = cc(BestRow, BestCol);
figure, imshow(A);
h = imrect(gca, [BestCol BestRow (ccols - 1) (crows - 1)]);
How can i change this code to get all possible best matches instead of one ? Thanks in advance!Pranay Wankhedehttps://kr.mathworks.com/matlabcentral/profile/authors/8644290-pranay-wankhedetag:kr.mathworks.com,2005:Question/4348532018-12-10T07:41:48Z2018-12-10T07:41:48ZWhy is mdlInitializeSizes() running multiple times?I am debugging by keeping breakpoints. Once after the completion of mdlInitializeSizes() debugging, if i press F5 to move to next breakpoint which i have placed in mdlStart(), it is not goint to mdlStart, it's again going back to the first breakpoint kept in mdlInitializeSizes().
Why is this happening?Naresh R Ahttps://kr.mathworks.com/matlabcentral/profile/authors/7523833-naresh-r-atag:kr.mathworks.com,2005:Question/4347912018-12-09T21:46:07Z2018-12-10T07:41:18ZHow do I save my data from each loop iteration into a single matrix?I am trying to save each calculated variables from each run of the loop into an output file.
I have the following code, however it overwrites the data for each loop so I am only left with the final iteration's data in the end.
for i=[1:no_lines]
x= -image_width/2 + (i-1)*d_x;
xdc_center_focus (emit_aperture, [x 0 0]);
xdc_focus (emit_aperture, 0, [x 0 z_focus]);
xdc_center_focus (receive_aperture, [x 0 0]);
xdc_focus (receive_aperture, focus_times, [x*ones(Nf,1), zeros(Nf,1), focal_zones]);
N_pre = round(x/(width+kerf) + N_elements/2 - N_active/2);
N_post = N_elements - N_pre - N_active;
apo_vector=[zeros(1,N_pre) apo zeros(1,N_post)];
xdc_apodization (emit_aperture, 0, apo_vector);
xdc_apodization (receive_aperture, 0, apo_vector);
[rf_data, tstart]=calc_scat(emit_aperture, receive_aperture, phantom_positions, phantom_amplitudes); %output to save
save(sprintf('rft%04d.mat',k),'rf_data','tstart')
x = x + d_x; %adds to the x for the next iteration
enddevon foggiohttps://kr.mathworks.com/matlabcentral/profile/authors/7370955-devon-foggiotag:kr.mathworks.com,2005:Question/4348412018-12-10T05:53:40Z2018-12-10T07:38:33ZHow to decrease the speed of an audio signal in MATLAB???Hello,
How can i decrease the speed of an audio signal??
is there any simle methode to do so?
should i alwayse use FFT ???
or it used only if I want to change the pitch of the voice?
fatima alansarihttps://kr.mathworks.com/matlabcentral/profile/authors/11473557-fatima-alansaritag:kr.mathworks.com,2005:Question/4347392018-12-09T14:37:26Z2018-12-10T07:37:24ZFinding the pseudo inverse of a matrixI'm trying to find the inverse of the following matrix
A =
-185.0685 185.0685 0
185.0685 -274.3238 89.2553
0 89.2553 -89.2553
Since A is a low-rank matrix , inv(A) doesn't work. So I tried the pseudo inverse, pinv(A) which takes the inverse of SVD of A.
However, A*pinv(A) isn't equal to identity. Are there alternative ways to find an inverse of A that will satisfy A*inverse(A) = Identity ?Deepa Maheshvarehttps://kr.mathworks.com/matlabcentral/profile/authors/8575091-deepa-maheshvaretag:kr.mathworks.com,2005:Question/4058902018-06-15T20:12:35Z2018-12-10T07:35:55ZSimEvents Conveyor belt with entities at different speedsHi All. I am using a SimEvents conveyor belt block, and would like to insert an entity at a different speed until it catches up to a minimum distance and then moves at the speed of the entity in front of it. I have no idea how to implement this. Any help would be appreciated.Etiennehttps://kr.mathworks.com/matlabcentral/profile/authors/1404326-etiennetag:kr.mathworks.com,2005:Question/4348502018-12-10T07:32:03Z2018-12-10T07:32:03ZHow to write a general equation and solving that using matrix method??T(m-1) - 2T(m) + T(m+1) + (delx*delx)*g/k =0 for m= 1 to 4
solving this i got the equations as
-2T(1) + T(2) = -16-50;
T(1)-2T(2) + T(3) = -16;
T(2)-2T(3) + T(4) = -16;
T(3)-2T(4) + T(5) = -16-4.44;
wanna solve this using matrix method.......
GURU PRASAATH Phttps://kr.mathworks.com/matlabcentral/profile/authors/14335987-guru-prasaath-ptag:kr.mathworks.com,2005:Question/2754792016-03-25T19:22:17Z2018-12-10T07:29:31Zwhy matlab is unable to solve these set of equations? syms X_1 X_2 X_3 X_4 Y_1 Y_2 Y_3 Y_4 a_1 a_2 a_3 a_4 a_5 a_6 a_7 a_8 a_9 b_1 b_2 b_3 b_4 b_5 b_6 b_7 b_8 b_9 c_1 c_2 c_3 c_4 c_5 c_6 c_7 c_8 c_9 d_1 d_2 d_3 d_4 d_5 d_6 d_7 d_8 d_9 e_1 e_2 e_3 e_4 e_5 e_6 e_7 e_8 e_9
%
first=a_1*X_1+a_2*X_2+a_3*X_3+a_4*X_4+a_5*Y_1+a_6*Y_2+a_7*Y_3+a_8*Y_4;
second=b_1*X_1+b_2*X_2+b_3*X_3+b_4*X_4+b_5*Y_1+b_6*Y_2+b_7*Y_3+b_8*Y_4+b_9;
third=c_1*X_3+c_2*X_4+c_3*Y_3+c_4*Y_4+c_5;
fourth=d_1*X_1+d_2*X_2+d_3*X_3+d_4*X_4+d_5*Y_1+d_6*Y_2+d_7*Y_3+d_8*Y_4+d_9;
fifth=e_1*X_3+e_2*X_4+e_3*Y_3+e_4*Y_4+e_5;
sixth=X_1*Y_2-X_2*Y_1;
seventh=X_3*Y_4-Y_3*X_4;
eighth=X_2*Y_3-X_3*Y_2;
%
S = solve([first,second,third,fourth,fifth,sixth,seventh,eighth], [X_1,Y_1,X_2,Y_2,X_3,Y_3,X_4,Y_4])
Meysam Ehttps://kr.mathworks.com/matlabcentral/profile/authors/7912282-meysam-etag:kr.mathworks.com,2005:Question/4345202018-12-07T23:34:35Z2018-12-10T07:26:36ZI am trying to write a code to solve a simple problem as shown below. I believe what am I am doing is correct up until i begin the spline fitting method. Am i interpolating correctly?Dd=[6 3 2 1.5 1.2 1.1 1.07 1.05 1.03 1.01];
c=[0.88 0.89 0.91 0.94 0.97 0.95 0.98 0.98 0.98 0.92];
a=[0.33 0.31 0.29 0.26 0.22 0.24 0.21 0.2 0.18 0.17];
ktoriginal=(c.*((0.5.*Dd)-0.5).^(-a)); %stress concentration factor for a stepped circular shaft
%based on table
%1)obtain an expression for c(Dd) annd a(Dd) with a 5th order polynomial
c5fitpoly = polyfit(Dd,c,5); %polyfit finds coefficents of a polynomial of degree 5 that fits a as a function of Dd
a5fitpoly = polyfit(Dd,a,5);
%next use polyval to determine the values for a and c using the coefficient
%vectors found for each
c5=polyval(c5fitpoly,Dd); %evalutes coefficent vector at each Dd
a5=polyval(a5fitpoly,Dd);
%calculating new kt values from fitted data
ktfitpoly5=(c5.*((0.5.*Dd)-0.5).^(-a5));
%comparing this kt with the original kt
polyerror=abs(ktoriginal-ktfitpoly5)';
%2)obtain an expression for c(Dd) annd a(Dd) with spline interpolation
cspline=interp1(c,Dd,'spline');
aspline=interp1(a,Dd,'spline');
ktspline=(cspline.*((0.5.*Dd)-0.5).^(-aspline));
splineerror=abs(ktoriginal-ktspline)';
disp('The error of kt using the polyfit method gives an error of:')
disp(polyerror)
disp('for each kt, whereas the error of kt using the spline method gives an error of:')
disp(splineerror)
disp('for each kt. In conclusion the first method is better to use as the errors are smaller.')
Caylyn MacDougallhttps://kr.mathworks.com/matlabcentral/profile/authors/13488151-caylyn-macdougalltag:kr.mathworks.com,2005:Question/280562012-02-04T20:41:27Z2018-12-10T07:24:49ZProblem in load library when using opencv and matlab<http://blog.cordiner.net/2010/02/15/opencv-viola-jones-object-detection-in-matlab/> describes how to use OpenCv with matlab.
I tried to execute the following command given at the end of the page :
opencvPath = 'C:\Program Files (x86)\OpenCV1.1';
includePath = fullfile(opencvPath, 'cxcore\include');
loadlibrary(...
fullfile(opencvPath, 'bin\cxcore110.dll'), ...
fullfile(opencvPath, 'cxcore\include\cxcore.h'), ...
'mfilename', 'proto_cxcore');
loadlibrary(...
fullfile(opencvPath, 'bin\cv110.dll'), ...
fullfile(opencvPath, 'cv\include\cv.h'), ...
'alias', 'cv110', 'includepath', includePath);
loadlibrary(...
fullfile(opencvPath, 'bin\highgui110.dll'), ...
fullfile(opencvPath, 'otherlibs\highgui\highgui.h'), ...
'alias', 'highgui110', 'includepath', includePath);
classifierFilename = 'C:/Program Files (x86)/OpenCV1.1/data/haarcascades/haarcascade_frontalface_alt.xml';
cvCascade = calllib('cv110', 'cvLoadHaarClassifierCascade', classifierFilename, ...
libstruct('CvSize',struct('width',int16(100),'height',int16(100))));
However,it returns an error ??? Error using ==> loadlibrary at 279
Microsoft Visual C++ 2005 or 2008 is required to use this feature.
Error in ==> opencv_test_prototype at 4
loadlibrary(...
I have Visual Studio 2010 Express as well as 2008 installed and have worked with MEX files before. I dont know how to proceed. Kindly helpchitrahttps://kr.mathworks.com/matlabcentral/profile/authors/3264302-chitratag:kr.mathworks.com,2005:Question/4348492018-12-10T07:19:10Z2018-12-10T07:19:10ZI am getting an error "Data 'hhatdot' is inferred as a variable size matrix, while its specified type is something else." My equation is "hhatdot =p*(u(t-hhat)-u(t-h))*udotfunction [hhatdot,bufferutnew] = fcn(ut,h,hhat,hmax,taus,udot,bufferut)
%#codegen
p = 0.05;
n=hmax/taus+1;
%%% updating input buffer
bufferutnew=zeros(1,2001);
bufferutnew(1,1:n-1)=bufferut(2:n);
bufferutnew(1,n)=ut;
indicehhat=floor(hhat/taus+1);
indicehhat=n-indicehhat;
indiceh=floor(h/taus+1);
indiceh=n-indiceh;
hhatdot = p*(bufferutnew(indicehhat:n)-bufferutnew(indiceh:n))*udot;
Chiliveri Vinodhttps://kr.mathworks.com/matlabcentral/profile/authors/13576941-chiliveri-vinodtag:kr.mathworks.com,2005:Question/4336082018-12-03T19:19:49Z2018-12-10T07:12:20ZImage authentication using color informationI am using attached script for splitting the image into 21 blocks (for Red, Green and Blue channels) and then compare each block pixel by pixel.
However, I want to do some changes as below:
1) How can I divide the image automatically into n number of equal blocks ( so I will just have to say 10 and it will divide the image into 10 equal size blocks).
2) I used isequal() function for comparison two blocks. How can I get the distance between two blocks. (Like Euclidean distance or something)
3) How to compare RGB histogram for each block. (Here I think it is possible to only compare the Y axis as X axis of the histogram will be 0 to 255 for all the blocks.) I know how to generate histogram but I dont know how to use that information for the comparison.
4) How can I keep some threshold e.g after comparison if all the blocks are matching > 98% then it is a true image OTW false image detected.
Thank you in advance. Devarshi Patelhttps://kr.mathworks.com/matlabcentral/profile/authors/13199198-devarshi-pateltag:kr.mathworks.com,2005:Question/4348442018-12-10T06:39:54Z2018-12-10T07:12:16ZHow to combine audio and video?it will run.. but not play the video... please tell me what the problem and how to resolve that?
videoFReader = vision.VideoFileReader('video1.avi');
[AUDIO,Fs] = audioread('audio1.wav');
videoFWriter = vision.VideoFileWriter('newvideo.avi','AudioInputPort',true);
videoFrame = step(videoFReader);
step(videoFWriter,videoFrame,AUDIO);
release(videoFReader);
release(videoFWriter);
keshav poojarihttps://kr.mathworks.com/matlabcentral/profile/authors/14328229-keshav-poojaritag:kr.mathworks.com,2005:Question/4348452018-12-10T06:42:56Z2018-12-10T07:04:34ZHow can I indent the output of display() and disp()?I am writing a small snippet to display trees of objects hierarchically.
I want to use standard Matlab functions as much as possible, therefore, I want to use disp() to display at least everything I don't care about implementing display() myself.
Is it possible to add, say, 10 spaces on the left of the output produced by disp(a)?
so that instead of:
>> a = 5
a =
5
I had
>> a = 5
a =
5
Lockywolfhttps://kr.mathworks.com/matlabcentral/profile/authors/3090160-lockywolftag:kr.mathworks.com,2005:Question/4346262018-12-08T18:10:38Z2018-12-10T07:01:31ZWhy does this produce an error?I am trying to create a function for a structure; I am not sure what is wrong with my syntax to where this is producing an error (this is the way I was taught it). MATLAB says that there is an error in the first function line:
MyBks = GetArrayBkStruct_('Title','ISBN','numberPages');
function[MyBks]=GetArrayBkStruct_('Title','ISBN','numberPages')
MyBks(1) = aBkStruct_('Neural Networks - Systematics','978-3-642-61068-4',502);
MyBks(2) = aBkStruct_('The Journey of Man - Genetics','978-0-691-11532-X',224);
MyBks(3) = aBkStruct_('Introduction to Neural Networks','978-3-642-57760-4',331);
MyBks(4) = aBkStruct_('Neural Networks Methodology','978-3-540-28847-3',498);
MyBks(5) = aBkStruct_('The Lost Symbol','978-1-4000-7914-8',639);
MyBks(6) = aBkStruct_('Neural Networks in Biomedicine','978-1-4471-0487-2',288);
MyBks(7) = aBkStruct_('Neural Networks: Computations','978-3-540-69226-3',300);
endDelaney Andersenhttps://kr.mathworks.com/matlabcentral/profile/authors/13429856-delaney-andersentag:kr.mathworks.com,2005:Question/4348032018-12-09T23:00:31Z2018-12-10T06:59:29ZHow to add scalar to empty matrix?Suppose you have the following for loop
result = zeros(5,1);
for k=1:5
result(k) = k^2 + ones(k-1,1)*5;
end
On the very first loop I will have 1^2 + []*5, and this will return an empty vector. I can obviously change the starting point for k to 2 to avoid this issue. However the problem I have is a more complicated version, and in some cases the starting point for the loop will be random. I would like to obtain k^2+[]*5 = k^2; treat the empty matrix as a zero, but matlab will just return an empty vector. Is there any way of converting an empty matrix into zero, and keeping the matrix if its not empty?Random goosehttps://kr.mathworks.com/matlabcentral/profile/authors/7414631-random-goosetag:kr.mathworks.com,2005:Question/4348282018-12-10T03:23:53Z2018-12-10T06:52:24ZPut matrix in cellI have this matrix T=[ 3 6 1 12 7 10 6 0 0 22 0 15;
2 4 4 3 2 4 5 0 0 20 0 4;
0 1 0 2 0 2 0 0 0 17 0 16;
0 5 0 6 0 7 0 0 0 6 0 0;
0 0 0 0 0 28 0 0 0 0 0 0]
I want to put each column of matrix T in cell c like this (the result should be)
c={[3,2], [6,4,1,5], [1,4], [12,3,2,6], [7,2], [10,4,2,7,28], [6,5],[ ],[ ],[22,20,17,6],[ ],[15,4,16]}
insted of zero column put [ ]
do not put zero in the cell
Naime Ahmadihttps://kr.mathworks.com/matlabcentral/profile/authors/13711668-naime-ahmaditag:kr.mathworks.com,2005:Question/4348462018-12-10T06:50:28Z2018-12-10T06:50:28ZSurface defect detection in rounded surfacesHello Dear Fellows.
I would like to ask for a advice. I have a 3D pointcloud data which represents the 3D surface of a part. What i am looking for is the defects, holes or scrathes on the surface. So far my only idea to fit a curve then calculate the points which are far away by a certain threshold. But unfortunetely, it doesnt work as I expected. Sometimes defects are so smooth that my fitting algorithm follows the defect.
The function that I am using are, polyfit to find the flat zone (something close to be flat) and fit( flat(:,1),flat(:,2),'poly3','Normalize','off','Robust','Bisquare'); to fit a curve. Can you please advice me ? Am I in the good path ? Any suggestions for different methods.
Ps: Parts, dimensions and angles are varying to each part. but the shape is more or less same.Emre Erdoganhttps://kr.mathworks.com/matlabcentral/profile/authors/13325872-emre-erdogantag:kr.mathworks.com,2005:Question/4348192018-12-10T01:34:53Z2018-12-10T06:46:48ZHow to finds the intersection points between rectangle foot print and line segment?This is the Code.
N = 50; % Number of events
X = 50; Y = 50;
P1x = rand(N,1) * X;
P1y = rand(N,1) * Y ; % initial point
L = lognrnd(2,0.7,[N,1]); % Sample track length
Theta = mod(normrnd(90,15,[N,1]),360);
dx = L.*cos(deg2rad(Theta - 90));
dy = L.*sin(deg2rad(Theta - 270));
P2x = P1x + dx; P2y = P1y + dy; % Final point
plot([0 X X 0 0],[0 0 Y Y 0]); hold on
plot(P1x,P1y,'ro')
plot([P1x P2x]',[P1y P2y]','-')
xlabel('X [km]'); ylabel('Y [km]');
xlim([-X/4 1.25*X]); ylim([-Y/4 1.25*Y])
%% Draw rectangles
Vx = [P1x P2x]' ;
Vy = [P1y P2y]' ;
t = 1./2 ;
% Loop to get normals
for i = 1:size(Vx,2)
W=LineNormals2D([Vx(:,i) Vy(:,i)]') ;
C = [[Vx(:,i) Vy(:,i)]+t*W ;
[Vx(:,i) Vy(:,i)]-t*W] ;
idx = boundary(C(:,1),C(:,2)) ;
plot(C(idx,1),C(idx,2),'k')
end
% GEt the line
lx = [(X+Y)/2.25, (X+Y)/3, (X+Y)/3, (X+Y)/4] ;
ly = [0, (X+Y)/10, (X+Y)/2.5, (X+Y)/2];
plot(lx,ly,'b')
I need to make code in MATLAB for this. Many thanks !!
Mosaruf Hussanhttps://kr.mathworks.com/matlabcentral/profile/authors/13934070-mosaruf-hussantag:kr.mathworks.com,2005:Question/4348272018-12-10T02:54:31Z2018-12-10T06:44:53ZCell to Table Conversion ProblemI wanted to convert a matlab cell array to matlab table in order to run my program accordingly. But, when I code and run it, certain columns (3 out of 32) are coming splitting. Please check the attached image. Fahad Parvez Mahdihttps://kr.mathworks.com/matlabcentral/profile/authors/13361322-fahad-parvez-mahditag:kr.mathworks.com,2005:Question/4348432018-12-10T06:26:07Z2018-12-10T06:40:24Zconvert cell 2 double with a table insideI have a matrix A containing cell array 12x1 which has table inside with dimension 86400x24 in each cell.
I would like to convert this matrix A to double. Is there any way?
Please note I want to keep the cells and hence table concantenated in the output. I do not wish to convert each
cell individually. I want to convert matrix A Megha Pandyahttps://kr.mathworks.com/matlabcentral/profile/authors/14301589-megha-pandyatag:kr.mathworks.com,2005:Question/4348242018-12-10T02:19:20Z2018-12-10T06:38:43ZHello. How to create such a matrix?1 0 2 0 ..
0 2 0 3 ..
2 0 3 0 ..
0 3 0 4 ..
3 0 4 0 ..
: : : :Azad Asadovhttps://kr.mathworks.com/matlabcentral/profile/authors/14335067-azad-asadovtag:kr.mathworks.com,2005:Question/4347482018-12-09T16:01:32Z2018-12-10T06:20:53ZGUI_1.get string from edit box 2.load .mat which has same name with string inputHI. I'm designing a gui.
I'm using r2018a and guide.
I want to input a string, which is a person's name, into a edit1 box, and then display that string on the edit2 box.
And I finally want to load .mat file named the string that I entered in edit1 box.
I can input a string and display, but I got error message on load.
Error code said, ' load should be string arrays or character arrays.'
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
user_name = get(handles.edit1, 'String');
set(handles.edit2, 'String', user_name)
user_data = load(user_name); %user_name is string type, right? what's the problem?
plot(handles.axis1, user_data)
Plz give me some advice. Appreciate in advance ;)MINKYUNG KIMhttps://kr.mathworks.com/matlabcentral/profile/authors/9879571-minkyung-kimtag:kr.mathworks.com,2005:Question/977742011-03-08T16:58:00Z2018-12-10T06:19:09ZWhy do I get an unexpected exception when activating MATLAB?When activating my MATLAB, I receive the error:
ERROR:
There was an unexpected exception:
c:\ program files\ matlab\ r2009a\ licenses\ license_username_123456_R2009a.lic (Access is denied) See the log file (C:\ Temp\ aws_username.log) for more details. MathWorks Support Teamhttps://kr.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:kr.mathworks.com,2005:Question/4348362018-12-10T05:03:40Z2018-12-10T06:15:14ZHow to change the audio from the video?i have one audio file and one video file.. But i dont know how to add the audio to video???
keshav poojarihttps://kr.mathworks.com/matlabcentral/profile/authors/14328229-keshav-poojaritag:kr.mathworks.com,2005:Question/4348392018-12-10T05:39:52Z2018-12-10T06:13:29Zhow to display a value in first column the second column number of times?suppose i have a column vector x=[1 2 3 4]; and y=[2 3 3.5 4]
i want the output as xy=[1 1 2 2 2 3 3 3 3 4 4 4 4];
the number 3.5 can be rounded off to a whole number. here ive taken it as 4.johnson saldanhahttps://kr.mathworks.com/matlabcentral/profile/authors/10681723-johnson-saldanhatag:kr.mathworks.com,2005:Question/4085452018-07-03T10:44:55Z2018-12-10T06:12:05ZBlock Error: Undefined function or variable. The first assignment to a local variable determines its class.Hi everyone,
I would like to store the attributes of entities that are *currently* being processes by a server block. In other words, when an entity enters a server block, its attribute is read and stored in a vector. When an entity exits a server block, it's attribute is read and removed from the aforementioned vector. It must be possible to read the vector from other blocks in the model.
I get the following error when I run my model: "Error in 'untitled/Entity Server' block. See Entry action line 5, column 12.
Caused by:
Undefined function or variable 'ServerStore'. The first assignment to a local variable determines its class.
Component:Simulink | Category:Block error"
I have made a basic model and attached it to this post. I have also added the relevant code below. Any help would be greatly appreciated.
Link to the model: https://drive.google.com/drive/folders/14KkH0H5JcUSwr-qqCHbPg7RUXHimafRw?usp=sharing
<</matlabcentral/answers/uploaded_files/123802/Capture.PNG>>
Entity Generator -> Event Actions -> Generate:
persistent ENTITYNR;
if isempty(ENTITYNR)
ENTITYNR=1;
entity.ENTITYNR=ENTITYNR;
else
ENTITYNR=ENTITYNR+1;
entity.ENTITYNR=ENTITYNR;
end
Server Block -> Event Actions -> Entry
%Record the attribute "ENTITYNR" from each entity that enters the server and store it in NROfNewEntityThatEntered
ENTITYNROfNewEntityThatEntered=entity.ENTITYNR;
%Store the "ENTITYNR" attributes of all the entities that are currently in the server in the vector ServerStore
if isempty(ServerStore)
%If it is the first entity to enter the server
ServerStore=ENTITYNROfNewEntityThatEntered
else
% If there are other entities in the server, add the attribute of the newly arrived entity to the existing ServerStore vector.
ServerStore=[ServerStore; ENTITYNROfNewEntityThatEntered]
end
Server Block -> Event Actions -> Exit
%Read the ENTITYNR attribute of the entity that is exiting the server
ENTITYNROfEntityThatExist=entity.ModuleID;
%Remove the ENTITYNR attribute from the list which is currently in the server
ServerStore = ServerStore(find(ServerStore~=ENTITYNROfEntityThatExist))
Striker121https://kr.mathworks.com/matlabcentral/profile/authors/5853526-striker121tag:kr.mathworks.com,2005:Question/4348422018-12-10T06:04:27Z2018-12-10T06:04:27ZHow do I organize(format) multiple text boxes and charts to an output figure?? Basically create a customized report as the output??Hello,
So I have a program that is going to generate a bunch and numbers and graphs for me.
Instead of having the format all this data everytime it's generated,, I would like to do this progmatically.
Ideally, I could do this in a similar manner to creating a GUI in the App builder, dragging and placing everything on the page, but I can't seem to find anything online about this.
I downloaded the Report builder add - on, but looks intense for what I'm trying to do.
Anyone have experience doing this out there?
Mark Lepagehttps://kr.mathworks.com/matlabcentral/profile/authors/10139950-mark-lepagetag:kr.mathworks.com,2005:Question/4348382018-12-10T05:34:17Z2018-12-10T05:53:55ZFinding the index (rank) of a specific number from a column Suppose I have a column B = [ 1 4 8 3 5 9]
and I have another vector = [ 8]
In this case, I want to find the rank where it's matched in the vector which should return a value of 3 (3rd). How do I do that ? Abbi Hashemhttps://kr.mathworks.com/matlabcentral/profile/authors/14329853-abbi-hashemtag:kr.mathworks.com,2005:Question/374572012-05-04T19:14:39Z2018-12-10T05:47:23Zcompute the unit vector given the angleHi guys,
How to compute the unit vector given the direction?
Is there any function in matlab to do this task.
Thankszhanghttps://kr.mathworks.com/matlabcentral/profile/authors/1170109-zhangtag:kr.mathworks.com,2005:Question/4348402018-12-10T05:46:39Z2018-12-10T05:46:39ZHow to modify the scaling values on yyaxis right? Hello,
I am trying to re-scale my yyaxis right values by making the values: 0_Bot, 0_Top, 17_Bot, 17_Top, -63_Bot, -63_Top, 90_Bot, and 90_top. I get lucky with my first few values actully marking the cuve, but as I go up my values don't match my graph anymore. If you can help me it will be greatly appreciated. Below is a copy of the function I am making for this graph, and in the attahments is a snip of my issue. (I am only concerned with the last part of my code under % Local Stresses)
-Robert
function z_plot(Strain_12,Strain_XY,Stress_XY,Stress_12,Thickness,p)
% This function will output all the graphs for sigma x,y and shear. As
% well as the strains for both Global and Local
Number_of_Ply = length(Stress_XY)/2;
% Global Strains
z_plot = -((Number_of_Ply)/2)*Thickness:Thickness:((Number_of_Ply)/2)*Thickness;
str_ar = ["_x","_y","_x_y"];
figure(4*p+1)
plot(Strain_XY,z_plot,'Linewidth',3);
title_str = "Global Strain in,"+char(949)+str_ar(p+1)+" Measured in mm";
title(title_str)
grid on
xlabel([char(949)+str_ar(p+1)+' Measured in \mu mm/mm'])
yyaxis left
ylabel('z, Measured in mm')
yyaxis right
ylabel('0 0 17 17 -63 -63 90 90')
% Local Strains
z_plot2 = -((Number_of_Ply)/2)*Thickness:Thickness/2:((Number_of_Ply)/2)*Thickness;
z_plot2 = repelem(z_plot2,2);
z_plot2(end) = [];
z_plot2(1) = [];
Local_Strains = repelem(Strain_12,2) ;
figure(4*p+2)
plot(Local_Strains,z_plot2,'Linewidth',3);
title_str = "Local Strains in,"+char(949)+str_ar(p+1)+" Measured in \mu mm/mm";
title(title_str)
grid on
xlabel([char(949)+str_ar(p+1)+' Measured in \mu mm/mm'])
yyaxis left
ylabel('z, Measured in mm')
yyaxis right
ylabel('0 0 17 17 -63 -63 90 90')
% Global Stresses
Global_Stresses = repelem(Stress_XY,2) ;
figure(4*p+3)
plot(Global_Stresses,z_plot2,'Linewidth',3);
title_str = "Global Stresses in,"+char(963)+str_ar(p+1)+" Measured in MPa";
title(title_str)
grid on
xlabel([char(963)+str_ar(p+1)+' Measured in MPa'])
yyaxis left
ylabel('z, Measured in mm')
yyaxis right
set(gca,'YTickLabel',{'0','0_B_O_T','0_T_O_P','17_B_O_T','-63_B_O_T','-63_T_O_P','90_B_O_T','90_T_O_P'})
% Local Stresses
Local_Stresses = repelem(Stress_12,2) ;
figure(4*p+4)
plot(Local_Stresses,z_plot2,'Linewidth',3);
title_str = "Local Stresses in,"+char(963)+str_ar(p+1)+" Measured in MPa";
title(title_str)
grid on
xlabel([char(963)+str_ar(p+1)+' Measured in MPa'])
yyaxis left
ylabel('z, Measured in mm')
yyaxis right
% % ylim([-.01 0.01])
% % yticks(-1:0.002:1)
set(gca,'YTickLabel',{'0','0_B_O_T','0_T_O_P','17_B_O_T','17_T_O_P','-63_B_O_T','-63_T_O_P','90_B_O_T','90_T_O_P'})
ylabel('Layer, \theta')
endRobert Floreshttps://kr.mathworks.com/matlabcentral/profile/authors/6790483-robert-florestag:kr.mathworks.com,2005:Question/4348322018-12-10T04:14:07Z2018-12-10T05:35:29Zglobal variables not cleared after 'clear;clc'I have a global variable. I run the code for several times. I put 'clear;clc' at the front. Strangely before the global variable is called, it already has a value. However I rerun it, it always has a value before its line is called. What could've happened?a ahttps://kr.mathworks.com/matlabcentral/profile/authors/11974203-a-atag:kr.mathworks.com,2005:Question/4107772018-07-17T17:00:15Z2018-12-10T05:34:24ZCan A Multicast Sender send to a tag which is dynamically determined from an attribute in the entity which it is sending?Can A Multicast Sender send to a tag which is dynamically determined from an attribute in the entity which it is sending?Elliott Rachlinhttps://kr.mathworks.com/matlabcentral/profile/authors/55024-elliott-rachlin