https://ww2.mathworks.cn/matlabcentral/answers/questionsMATLAB Answers — New Questions2021-05-13T06:40:08Ztag:ww2.mathworks.cn,2005:Question/8289832021-05-13T06:03:32Z2021-05-13T06:40:08Zconversion of date from yyyymmddHHMMSS format to yymmddHHMMSS format.Hi all can anyone please help with the conversion of date from yyyymmddHHMMSS format to yymmddHHMMSS format.
for example I want to change column 1 in the following dataset: (e.g row 1 shoud be 200723000000)
'2020,07,23,00,00,00' -0.800000000000000
'2020,07,23,00,00,10' -0.800000000000000
'2020,07,23,00,00,20' -0.700000000000000
'2020,07,23,00,00,30' -0.700000000000000
'2020,07,23,00,00,40' -0.700000000000000
'2020,07,23,00,00,50' -0.800000000000000
'2020,07,23,00,01,00' -0.700000000000000
'2020,07,23,00,01,10' -0.700000000000000
'2020,07,23,00,01,20' -0.700000000000000
'2020,07,23,00,01,30' -0.600000000000000
'2020,07,23,00,01,40' -0.600000000000000
'2020,07,23,00,01,50' -0.600000000000000
'2020,07,23,00,02,00' -0.500000000000000
'2020,07,23,00,02,10' -0.500000000000000
'2020,07,23,00,02,20' -0.500000000000000
'2020,07,23,00,02,30' -0.600000000000000
'2020,07,23,00,02,40' -0.500000000000000
'2020,07,23,00,02,50' -0.500000000000000
'2020,07,23,00,03,00' -0.500000000000000
'2020,07,23,00,03,10' -0.500000000000000
'2020,07,23,00,03,20' -0.500000000000000Remember Samuhttps://ww2.mathworks.cn/matlabcentral/profile/authors/22265979tag:ww2.mathworks.cn,2005:Question/8289932021-05-13T06:30:54Z2021-05-13T06:39:09Znested if-else inside nested if-elseIn the following program it showed error in line 22.If elseif statement can't be used in this way,please suggest alternative way.
%code
function output = blur(img,w)
img(:) = double(img(:))+1;
[row col] = size(img);
output = zeros(row, col);
for i=1:row
for j=1:col
if (i-w)<1
if (j-w)<1
A = img([1:i+w,1:j+w]);
k = mean( img ,'all');
output(i,j) = k;
elseif (j+w)>col
A = img([1:i+w,j-w:col]);
k = mean( img ,'all');
output(i,j) = k;
else
A = img([1:i+w,j-w:j+w]);
k = mean( img ,'all');
output(i,j) = k;
end
elseif (i+w)>row
if (j-w)<1
A = img([i-w:row,1:j+w]);
k = mean( img ,'all');
output(i,j) = k;
elseif (j+w)>col
A = img([i-w:row,j-w:col]);
k = mean( img ,'all');
output(i,j) = k;
else
A = img([i-w:row,j-w:j+w]);
k = mean( img ,'all');
output(i,j) = k;
end
else
if (j-w)<1
A = img([i-w:i+w,1:j+w]);
k = mean( img ,'all');
output(i,j) = k;
elseif (j+w)>col
A = img([i-w:i+w,j-w:col]);
k = mean( img ,'all');
output(i,j) = k;
else
output(i,j) = mean(img(i-w:i+w,j-w:j+w));
end
end
end
end
output(:) = uint8(round(output(:)-1));
Error: File: blur.m Line: 22 Column: 5
Illegal use of reserved keyword "elseif".
Kazmir Fahrierhttps://ww2.mathworks.cn/matlabcentral/profile/authors/21844121tag:ww2.mathworks.cn,2005:Question/8268752021-05-10T22:57:00Z2021-05-13T06:34:50ZAutomatically select and name variables from import file (.xlsx) Hello,
I have an excel file with a column of variables. It looks like this:
The sequence is approx. 0.0237, -0.0016, 0.0018, 0.0239. Which should be named A, B, C, D. This sequence repeats in the same order 50 times (A1,B1,C1,D1, A2, B2, C2, D2, etc), but the values are different each time and the number of cells for A1, B1, etc varies. A and D are always in the range of 0.0001 to 0.0320, while B and C are always in the range 0.0010 to 0.0020.
At the moment, I am highlighting the cells from Import Data and naming them one by one.
I would like to automatically select 10 cells before B1, and name those A1. Automatically select all the cells for B1 and name them B1. Automatically select all the cells for C1 and name them C1. Finally, automatically select 10 cells after C1 and name them D1. This would be repeated for the other 49 times.
Any help would be appreciated!
Thank you.meryem berradahttps://ww2.mathworks.cn/matlabcentral/profile/authors/6921846tag:ww2.mathworks.cn,2005:Question/8278052021-05-11T21:35:55Z2021-05-13T06:30:00ZAdding images to reach a final composite.Hello all, I am attempting to add several photos such that I can see the distribution of particles in a laser sheet as they exit a converging nozzle. I am having issues arriving at a final composite photo that contains the particles without over-saturating. Below I will post a few of the base photos (there are really several hundred). I will also show two methods I tried out but to no avail. I will detail the methods below next to their code.
Background photo (2/3 of the photos in the dataset are identical to this because the camera was not in sync with the laser pulses):
Particles photo 1:
Particles photo 2:
Method 1: In method 1 I converted the grayscale .bmp images to double (matrices) before handling them and converted them back mat2gray() before using imshow(). I noticed that the particles were bright when the first few photos were added, but they became dark as I progressed the loop. I also attemped a run involving subtracting the background image, but this led to worse results, as everything approached black (commented out in the bottom for-loop).
clear; clc; close all;
image_folder = 'E:\PIV Shakedown 1\run3\Photos'; % Path of photos
filenames = dir(fullfile(image_folder,'*.bmp'));
nfiles = length(filenames);
images = cell(1,nfiles);
background = imread('background.bmp'); % Background photo with laser off
background = double(background);
for n = 1:nfiles
f = fullfile(image_folder,filenames(n).name);
current_image = imread(f);
current_image = double(current_image);
images{n} = current_image; % Several hundred photos, some with particles and some without
end
addition = images{1}; % Preparing the first photo for adding
for j = 1:88%nfiles-1
addition = addition+images{j+1}; % -background; % Adding every photo in double format to prevent oversaturation (grayscale caps at 255)
figure() % For debugging purposes
imshow(mat2gray(addition)) % For debugging purposes
end
background_avg = addition/(j+1); % Creates a background based upon every photo summed in addition
% ISSUE: The below change to addition is pointless because background_avg*(j+1) = addition, thus the following subtraction = 0
% addition = addition - background_avg*(j+1); % Can use background or background_avg
background_avg = mat2gray(background_avg);
figure()
imshow(mat2gray(addition))
figure()
imshow(background_avg)
figure()
imshow(mat2gray(background))
Resulting addition photos (at different loop iterations)
RUN 1: First addition involves a photo with no particles and one with sparse particles
j=1, first addition: Note that the particles are dimmer. This addition inluded a bright photo like the ones above.
j=5, fifth addition: Notice that the particles are even more dim (even though more particles are added on this 5th addition). Ideally the final photo will look like this but the particles wil be VERY obvious. Instead, after about 50 pictures you cannot distinguish any particles at all due to their continual approach to black in these photos.
Method 2: In method 2 I did not convert the photos to doubles, so I ran into the issue that is the grayscale range (0-255). I.E. 233+234 = 255 due to the cap.
%% Non-Normalizing
clear; clc; close all;
image_folder = 'E:\PIV Shakedown 1\run3\Photos'; % Path of photos
filenames = dir(fullfile(image_folder,'*.bmp'));
nfiles = length(filenames);
background = imread('background.bmp'); % Background photo
images = cell(1,552);
for n = 1:nfiles
f = fullfile(image_folder,filenames(n).name);
current_image = imread(f);
images{n} = current_image;
end
addition = images{1};
for j = 1:250%nfiles-1 %nfiles when using all images
addition = imadd(addition,images{j+1});
addition = imsubtract(addition,background);
% figure()
% imshow(addition)
end
figure()
imshow(addition)
After 8 iterations of Method 2:
After 250 iterations of Method 2: Note that it isn't white purely due to particles, but the entire image creeps towards being white.
I appreciate any help!Addison Collinshttps://ww2.mathworks.cn/matlabcentral/profile/authors/18815680tag:ww2.mathworks.cn,2005:Question/8267052021-05-10T17:29:04Z2021-05-13T06:28:34ZSimulink from where to get Model Linearizer i cant find control system where to find all these or i need to buy them from add ons from where to get Model Linearizer i cant find control system where to find all these or i need to buy them from add ons Bader Herzallahhttps://ww2.mathworks.cn/matlabcentral/profile/authors/17716299tag:ww2.mathworks.cn,2005:Question/8289882021-05-13T06:28:21Z2021-05-13T06:28:21ZExternal Mode error for de10 nanoI have created the hardware configurations reuired following the tutorial here: https://www.mathworks.com/videos/custom-target-development-for-arm-cortex-a-part-6-external-mode-feature-121177.html?s_tid=vid_pers_recs
While trying to test external mode, it fails with the following error:
Error occurred while executing External Mode MEX-file 'ext_comm': Failed to connect to the target. Possible reasons for the failure:
a) The target is not switched on.
b) The target is not connected to your host machine.
c) The application for the model is not running on the target. You might have clicked the Stop button. If the Run button is not dimmed, click it. Otherwise, click the Build button, which downloads and runs your application on the target.
Caused by: An error occurred attempting to open an rtIOStream. More detail may be reported in the MATLAB command window
Which is weird because none of the reasons (a), (b) and (c) is true.anuj maheshwarihttps://ww2.mathworks.cn/matlabcentral/profile/authors/20968142tag:ww2.mathworks.cn,2005:Question/8243952021-05-07T15:46:33Z2021-05-13T06:26:40ZMatlab: Split and Plot the training data set and test data set.Hi Everyone
Thanks for any Help
i need some solution for this practice.
First, divide the data into two parts: training data (Train) and test data. Consider 30% of the data for the test set and 70% as the training set.
Second, This segmentation should be completely random without duplicate data. In other words, none of the randomly selected test set data should be present in the training set and also the data in the test set should not be duplicate. (Use efficient functions in MATLAB for this purpose)
--> Perform the regression for the polynomial degree from degree 1 to degree 100 and display the results of these 100 experiments in the plot below.
--> This example plot shows the MSE error for each degree of polynomial for both the training set and test set.
i have generated the data in one dimension using the following code :
rng(914163506);
temp=0:.15:2*pi;
x = sin(temp)+.2*randn(size(temp));arash Mohahttps://ww2.mathworks.cn/matlabcentral/profile/authors/22402017tag:ww2.mathworks.cn,2005:Question/8244802021-05-07T17:29:26Z2021-05-13T06:21:36ZIncreasing the number of iterations in GeneralizedLinearModel.fitDear Experts,
I am fitting a matrix of predictors (desmat) to a timeseries (ts) and to do it I use a GeneralizedLinearModel object as follows:
m = GeneralizedLinearModel.fit(desmat, ts);
However, I often get the following warning:
Warning: Iteration limit reached.
> In glmfit (line 332)
In GeneralizedLinearModel/postFit (line 605)
In classreg.regr.FitObject/doFit (line 95)
In GeneralizedLinearModel.fit (line 887)
I have to use GeneralizedLinearModel.fit instead of glmfit because I am also running some contrasts between the model parameters down the line.
My question is this: how can I increase the number of maximum iterations in this fit method, so I can try to make my model converge? Alternatively, is there a way to do a contrast of coefficients that returns p-values using the glmfit function?
Thank you very much,
Leonardo TozziLeonardo Tozzihttps://ww2.mathworks.cn/matlabcentral/profile/authors/12009518tag:ww2.mathworks.cn,2005:Question/8246902021-05-08T00:18:52Z2021-05-13T06:11:23ZShallow Neural Networks trainbr trainlm alternativesI've found the results from trainbr to be much better than trainlm for my particular use but trainbr is taking a couple hours during the training process and can't take advantage of a GPU.
Can you recommend any alternatives to trainbr that might provide similar quality results yet run faster?
Thank you!Brenthttps://ww2.mathworks.cn/matlabcentral/profile/authors/5323111tag:ww2.mathworks.cn,2005:Question/1166982014-02-19T05:00:00Z2021-05-13T06:08:37Z如何在 64 位 Windows 上设置 Microsoft Visual Studio 2008 Express Edition 与 MATLAB 7.7 (R2008b) 一起使用？我想在 64 位 Windows 上设置 Microsoft Visual Studio 2008 Express Edition 与 MATLAB 7.7 (R2008b) 一起使用。MathWorks Support Teamhttps://ww2.mathworks.cn/matlabcentral/profile/authors/4622813tag:ww2.mathworks.cn,2005:Question/4269802018-10-30T17:48:00Z2021-05-13T06:04:21ZHow to find the mean of one column based on the value in another columnI want to find the mean of the values in the second column only for the rows which have the value 3 in column 10
I have tried mean = mean(data(data(:,10)==3,8))Catherine Branterhttps://ww2.mathworks.cn/matlabcentral/profile/authors/13660920tag:ww2.mathworks.cn,2005:Question/1166942014-02-19T05:00:00Z2021-05-13T06:03:55Z为什么在 64 位 Windows Vista、7 或 Server 2008 上安装 MATLAB 时会遇到 Visual C++ Redistributable 错误 1935？我在 Windows 上安装 MATLAB 时遇到以下错误：
ERROR: 错误 1935。安装程序集期间出错
'Microsoft.VC80.ATL.type="win32",version="8.0.50727.762".publicKeyToken="1fc8b3b9a1e18e3b".processorArchitecture="amd64"'.
请参考帮助和支持了解详细信息。MathWorks Support Teamhttps://ww2.mathworks.cn/matlabcentral/profile/authors/4622813tag:ww2.mathworks.cn,2005:Question/7737572021-03-15T17:10:58Z2021-05-13T05:58:30ZWhy does PowerGUI Library Link keeps disabling?Hi,
I have a simulink model that I copied from another model. I did some changes and when I run the model, the broken chain appears in the powerGUI block and it says "Disabled library link: powerlib/powergui". Model works though (much slower than the original model). No error happens when this link is disabled. I can then either run it again disabled or restore the link and run it but after compiling it disables the link again.
How can I prevent this from happening? Should I worry about this? Is this the reason why my model is much slower than the original one?
Note: When running the model without the powergui, error comes up notifiying that this block is required.Juan Lopezhttps://ww2.mathworks.cn/matlabcentral/profile/authors/20442483tag:ww2.mathworks.cn,2005:Question/8227102021-05-06T05:06:14Z2021-05-13T05:58:28ZHow to deploy Machine learning model to ARM Cortex - 32 bit Microcontrollers ?Hello Team,
Thanks a lot for free introductory courses on Machine learning and Deep Learning.
Need info on how to deploy Machine learning model on my ARM CORTEX - 32 bit Microcontroller, i have below querries-:
1.) Is there any tools available in MATLAB to make models faster and smaller(Model Optmization)?
2.) How to convert a ML Model to C array or .c, .h files to integarte/compile them along with my project written in C?t
Need your help to clarify above querries ASAP, will be of great help.
Thank You
Deep SinghDeep Singhhttps://ww2.mathworks.cn/matlabcentral/profile/authors/22371773tag:ww2.mathworks.cn,2005:Question/8263552021-05-10T10:36:07Z2021-05-13T05:47:31ZBuild model detection after features extractionHello,
I'm trying to code a nose detection function from a IR video.
I extracted 2 frames from the video and foud the features and compared between them.
ref_img = imread('frame_1.png');
ref_img_gray=rgb2gray(ref_img);
ref_pts=detectSURFFeatures(ref_img_gray);
[ref_features,ref_validPts]=extractFeatures(ref_img_gray,ref_pts);
figure; imshow(ref_img);
hold on; plot(ref_pts.selectStrongest(50));
image=imread('frame_50.png');
I=rgb2gray(image);
I_pts=detectSURFFeatures(I);
[I_features,I_validPts]=extractFeatures(I,I_pts);
figure;imshow(image);
hold on; plot(I_pts.selectStrongest(50));
index_pairs=matchFeatures(ref_features,I_features);
ref_matched_pts=ref_validPts(index_pairs(:,1)).Location;
I_matched_pts=I_validPts(index_pairs(:,2)).Location;
close all
figure,showMatchedFeatures(image,ref_img,I_matched_pts,ref_matched_pts);
Here the figure obtained :
What I have to do as a next step ? We can see from the figure that we got the 2 nostrils as features, so how to train a model a got a function that tracks the region for all the frames ?
thank youIlan Moshehttps://ww2.mathworks.cn/matlabcentral/profile/authors/17080405tag:ww2.mathworks.cn,2005:Question/8249052021-05-08T09:10:04Z2021-05-13T05:38:07ZSimulink does not work (Ubuntu 20.04)
These are the error messages when I open simulink on Matlab R2021a on my Ubuntu 20.04. I recently installed both the OS and MATLAB.
When I dismiss these messages and try creating a blank model, I get another error:
Any suggestions or fixes are much appreciated. William Ebenezarajhttps://ww2.mathworks.cn/matlabcentral/profile/authors/17466081tag:ww2.mathworks.cn,2005:Question/8255702021-05-09T10:30:54Z2021-05-13T05:36:55ZHow to speed up the following Matlab script? Can anyone suggest me to speed up the process?In the following scripts, I get expected result but the process is very slow. Is there any other way to make the execution faster/fastest ?
clc; close all; clear all;
load Array.mat; % B is the name
per_group = 1000;
[row,col]=size(B); % val would be a matrix of size (C*C)
limit=row/per_group;
value=cell(1,limit);
count=0;
val = zeros(col); % Memory Pre-allocation
for kk = 1:per_group:row
count=count+1;
group_end = min(row, kk+per_group-1);
for jj= 1:col
f1 = A(kk:group_end,jj);
for i=(jj+1):col
f2= A(kk:group_end,i);
[Pyy,freq]=cpsd(f2,f2,hanning(512),[],512,500);
[Pxy,freq]=cpsd(f1,f2,hanning(512),[],512,500);
[Pxx,freq]=cpsd(f1,f1,hanning(512),[],512,500);
coh=(Pxy)./sqrt(Pxx.*Pyy);
realCoh=real(coh(42));
val(jj,i)=realCoh;
end
end
value{count}=val+val'+eye(col)
end
SAhttps://ww2.mathworks.cn/matlabcentral/profile/authors/21475995tag:ww2.mathworks.cn,2005:Question/8289432021-05-13T03:10:40Z2021-05-13T05:35:25ZI have this for loop, and it seems to not end. for i=1:n
Phi1=1;
Phi2=1;
gamma1calc(i)=exp(alpha/(1+(alpha/beta)*(x1(i)/x2(i)))^2);
gamma2calc(i)=exp(beta/(1+(beta/alpha)*(x2(i)/x1(i)))^2);
Pcalc(i) = ((x1(i)*gamma1calc(i)*P1sat)/(Phi1))+((x2(i)*gamma2calc(i)*P2sat)/(Phi2));
AE1(i)=1;
while AE1(i) > 0.0001
y1calc(i) = (x1(i)*gamma1calc(i)*P1sat)/(Phi1);
y2calc(i) = 1-y1calc(i);
Phi1calc(i)=exp((B1.*(Pcalc(i)-P1sat)+Pcalc(i).*y2calc(i).^2.*(2.*B12-B1-B2))./(R*T));
Phi2calc(i)=exp((B2.*(Pcalc(i)-P2sat)+Pcalc(i).*y1calc(i).^2.*(2.*B12-B1-B2))./(R*T));
Pnew(i) = ((x1(i)*gamma1calc(i)*P1sat)/Phi1calc(i))+((x2(i)*gamma2calc(i)*P2sat)/Phi2calc(i));
AE2 (i)=abs(Pnew(i)-Pcalc(i));
if AE2(i) > 0.0001
Pcalc(i)=Pnew(i);
end
end
Pcalc(i)=Pnew(i);
endJosiah Jarenee Comiahttps://ww2.mathworks.cn/matlabcentral/profile/authors/20581858tag:ww2.mathworks.cn,2005:Question/8218552021-05-05T04:34:40Z2021-05-13T05:34:53ZSolving second-order non-linear PDEI am trying to solve this second order differential equation
Where
is a function of space () and time (),
is a function of space. This is a known ramp function that starts at 0 and increases to a fixed value.
is constant and is
is a constant.
With initial conditions at of ,
I have tried using pdepe but I am struggling to get it into a form that is acceptable. I have also attempted reformating it as an ODE but wasn't able to get any resonable solutions.
Is this a feasible equation that can be solved with Matlabs solvers?
ThanksFelixhttps://ww2.mathworks.cn/matlabcentral/profile/authors/13064882tag:ww2.mathworks.cn,2005:Question/8254752021-05-09T06:50:41Z2021-05-13T05:32:50ZPlease, someone help me to understand this code.I'm a beginner in MATLAB and i have to understand this code as it's important for my project. I request you guys to please help me to understand this code.
ec=xlsread('sumit_ecg.xlsx','B3:B1000003');
figure;
plot(ec);
j=1;
for i=2:length(ec)-1;
if ec(i-1)< ec(i) && ec(i+1)<ec(i);
ecgy1(j)=ec(i);
ecgx1(j)=i;
j=j+1;
end
end
figure;plot(ec); hold on;
plot(ecgx1,ecgy1,'*');
j=j+1;
for i=1:length(ecgy1);
if ecgy1(i)>=2;
ecgy2(j)=ecgy1(i);
ecgx2(j)=ecgx1(i);
j=j+1;
end
end
figure;plot(ec); hold on;
plot(ecgx2,ecgy2,'*');Mohan Dubeyhttps://ww2.mathworks.cn/matlabcentral/profile/authors/22484515tag:ww2.mathworks.cn,2005:Question/8226852021-05-06T04:45:47Z2021-05-13T05:32:24Z3D Polynomial RANSACHow would I apply polynomial RANSAC to plot a curved line given a 3d point cloud? Is there a way to get 3D curved fit?
Is there a way to plot a 3D line, maybe given 2 polynomial equations? (ex. using x-y and x-z equation)MJhttps://ww2.mathworks.cn/matlabcentral/profile/authors/8648523tag:ww2.mathworks.cn,2005:Question/4486562019-03-06T18:58:44Z2021-05-13T05:31:44Zadding legend that is comes from a variableI have a variable that looks like this:
eta = [0.4843 0.3927];
Note that I access both of these later in a loop.
How can I create a legend after my plot command to automatically make the first one the first eta entry (0.4843) and the second line in the plot to be the second eta entry (0.3928)? How can I do this dynamically so that it is automated if I change the values in eta or if I make it have more numbers?Benjaminhttps://ww2.mathworks.cn/matlabcentral/profile/authors/4307919tag:ww2.mathworks.cn,2005:Question/8264352021-05-10T12:07:21Z2021-05-13T05:31:29ZExport LaTeX labels in figures to IllustratorRecently, I started exporting my Matlab figures to illustrator in order to touch them up for publication. I export the figures using: Save as --> .EMF and .EPS. However, when I open either file in Illustrator, all the text in the images, axis labels/legend/etc, is converted to outlines. All text in my images is set to the LaTeX format, however I do have the LaTeX fonts installed in illustrator. What can I do to solve this issue?Daniel Faasenhttps://ww2.mathworks.cn/matlabcentral/profile/authors/16897207tag:ww2.mathworks.cn,2005:Question/580862013-01-06T17:05:40Z2021-05-13T05:29:57ZIs there a way of georeferencing images in Matlab in a similar way to ESRI ArcMap? Is there a way of georeferencing images in Matlab in a
similar way to ESRI ArcMap? Basically, I have a list of
UTM coordinates, and a corresponding list of image pixel
coordinates. I want to reference these pixel coordinates
to the UTM coordinates, and produce a worldfile based on
thisAbdul Razak Alhassanhttps://ww2.mathworks.cn/matlabcentral/profile/authors/3578747tag:ww2.mathworks.cn,2005:Question/8288782021-05-13T00:53:12Z2021-05-13T05:29:43ZSummation of different size matrices I need to summate a small (1x3 matrix) with a large (457x46 matrix). Where eps_x0, exps_y0,eps_xy0 are indivudal numbers, and "curve" values differ per x,y values from the mesh grid. Truth be told I do not even know what the meshgrid does. Coding is very foreign to me, any help would be appreciated. All D values, a and b, and p0 are known, just x and y vary per case.
a = 1.14;
b = 0.57;
[X,Y] = meshgrid(0:0.025:a, 0:0.00125:b);
curve_x = (12.25*p0*((Y.^2-b*Y).^2).*(6*X.^2 - 6*a*X + a^2)/((7*D11*b^4)+4*a^2*b^2*(D12+2*D66)+(7*D22*a^4)));
curve_y = (12.25*p0*((X.^2-a*X).^2).*(6*Y.^2 - 6*b*Y + b^2)/((7*D11*b^4)+4*a^2*b^2*(D12+2*D66)+(7*D22*a^4)));
curve_xy = (49*p0*(2*X.^3-3*a*X.^2+a^2*X).*(2*Y.^3-3*b*Y.^2+b^2*Y)/((7*D11*b^4)+4*a^2*b^2*(D12+2*D66)+(7*D22*a^4)));
eps_x0 = eps_0(1)
eps_y0 = eps_0(2)
eps_xy0 = eps_0(3)
eps_x = eps_x0 + curve_x;
eps_y = eps_y0 + curve_y;
eps_xy = eps_xy0 + curve_xy;David Krousehttps://ww2.mathworks.cn/matlabcentral/profile/authors/19475175tag:ww2.mathworks.cn,2005:Question/8289782021-05-13T05:23:43Z2021-05-13T05:26:23ZHierarchical Clustering Question, pleaseWhen I was running Hierarchical Clustering, I had some problem
There are some method, called 'average' 'centroid' ' 'complete' 'median' 'single' 'ward' 'weighted'
Z = linkage(y,'?'), ?=average; centroid; complete; median; single; ward; weighted
but my professor said that there are some methods, called 'feasible method' and ' feasible group average method '.
i don't know the code what i have to type in this Z = linkage(y,'?'),
the picture is the formula
I try to translate from Chinese
thanks for your response
Wade Chenhttps://ww2.mathworks.cn/matlabcentral/profile/authors/22533364tag:ww2.mathworks.cn,2005:Question/8287152021-05-12T20:00:11Z2021-05-13T05:18:22ZSet non-uniform axis - extension of certain part of y-axis.I want to extend a certain section of the y-axis in a contour plot. For e.g., 0 to 200 m and 200 to 400 m depths are extended to different extents in a plot as shown in the attached figure.
Is there a direct function to do so?
If not the extension of multiple sections of axis, 'function' for extension of one section only shall also work.Himanshu Saxenahttps://ww2.mathworks.cn/matlabcentral/profile/authors/21452112tag:ww2.mathworks.cn,2005:Question/8263902021-05-10T11:17:48Z2021-05-13T05:16:56ZMalwarebytes thinks these Matlab files are malwareMalwarebytes flagged the 4 files below from my R2020b installation. Has anyone else experienced this? Can I safely assume it's a false alarm?
C:\PROGRAM FILES\MATLAB\R2020B\BIN\WIN64\LIBMWINT16TOUINT16.DLL
C:\PROGRAM FILES\MATLAB\R2020B\BIN\WIN64\LIBMWUINT16TOINT16.DLL
C:\PROGRAM FILES\MATLAB\R2020B\BIN\WIN64\LIBMWINT16TOUINT16.DLL
C:\PROGRAM FILES\MATLAB\R2020B\BIN\WIN64\LIBMWUINT16TOINT16.DLLMatt Jhttps://ww2.mathworks.cn/matlabcentral/profile/authors/1440443tag:ww2.mathworks.cn,2005:Question/8289732021-05-13T05:16:56Z2021-05-13T05:16:56ZHow to apply RBF kernel function in k means cluster? Here is the codeThis is the code
grayImage= imread('CYST RENAL -87.jpg');
g = rgb2gray(grayImage);
g = double(g);
sigma = 0.4;
[n,d] = size(g);
nms = sum(g'.^2);
Ks = exp(-(nms'*ones(1,n) -ones(n,1)*nms + 2*g*g')/(2*sigma^2));
[m n]=kmeans(Ks,3);
m=reshape(m,size(Ks,1),size(Ks,2));
B=labeloverlay(Ks,m);
figure;
imshow(B);
I am unable to solve this error. Plshelp me to solve this error and explain how to apply kernel functions in k means clusetering
Error using reshape Number of elements must not change. Use [] as one of the size inputs to automatically calculate the appropriate size for that dimension.MINO GEORGEhttps://ww2.mathworks.cn/matlabcentral/profile/authors/18929086tag:ww2.mathworks.cn,2005:Question/8289682021-05-13T05:01:50Z2021-05-13T05:01:50ZDisabled - No sandbox or build area pathMatlab is crashing when open from shortcut and generates matlab_crash_dump files in %temp% folder. How to resolve it?Harsha Mhttps://ww2.mathworks.cn/matlabcentral/profile/authors/16423424tag:ww2.mathworks.cn,2005:Question/8161602021-04-28T19:55:02Z2021-05-13T05:00:52ZCreate .xyz file from grid dataI have data x(100x1), y(100x1), z(100x100). How can I get data in triplet form (x,y,z)?Laxmikant Manehttps://ww2.mathworks.cn/matlabcentral/profile/authors/15154067tag:ww2.mathworks.cn,2005:Question/1029462013-09-13T14:30:00Z2021-05-13T04:59:35ZWhy does the MATLAB desktop look blurry when using MATLAB R2013b or R2014a on my Mac with Retina display?The text in MATLAB R2013b and R2014a looks visually less crisp on my Mac computer with a Retina Display.MathWorks Support Teamhttps://ww2.mathworks.cn/matlabcentral/profile/authors/4622813tag:ww2.mathworks.cn,2005:Question/8283752021-05-12T13:43:05Z2021-05-13T04:56:37ZHigh-pass filterHello,
I'm working on acceleration signals coming from an accelerometer that has a sensitivity change of 0% from 2 Hz to 10000 Hz. When I perform the FFT of one this accelerometric signals I often obtain strong low frequency contents close to 0.1 Hz. I would like to cut away all the frequencies before 2 Hz because I don't think they are correct. The code I used is:
Fca=2; %cutoff frequency
[z,p,k]=butter(8,Fca/(Fsa/2),'high');
sos=zp2sos(z,p,k);
%fvtool(sos,'Analysis','freq')
xafiltfilt=filtfilt(sos,g,xa);
%figure;
%plot(ta,xa,ta,xafiltfilt);
%grid on
%title('xa (accelerometric signal)')
%xlabel('t (s)')
%ylabel('Acceleration (g)')
%legend({'Original xa Signal','Actual xa Signal (filtered and realigned signal)'});
%saveas(gcf,'x_acc_filt_comp','jpg')
Xaf=fft(detrend(xafiltfilt),NFFT2_acc)/Na;
figure;
plot(fa,2*abs(Xaf(1:NFFT2_acc/2+1)))
grid on
title('Single-Sided Amplitude Spectrum of xa(t) filtered and realigned Signal')
xlabel('f (Hz)')
ylabel('Xa_filtered(f)')
I was wondering if this type of filter may be adequate.
Thank you very much,
GuglielmoGuglielmo Giambartolomeihttps://ww2.mathworks.cn/matlabcentral/profile/authors/7868344tag:ww2.mathworks.cn,2005:Question/8289632021-05-13T04:56:18Z2021-05-13T04:56:18ZQuestion about symbolic differential expression - sequence of calculation in live editorI have an symbolic expression obtained from Matlab as
y =\frac{\partial}{\partial x} \sigma_1\sigma_2
what is the sequence of calculation in Matlab symbolic toolbox? should it be
y = (\frac{ \partial}{\partial x} \sigma_1)\sigma_2 % option 1
or
y = \frac{ \partial}{\partial x} (\sigma_1\sigma_2) % option 2?Kuifenghttps://ww2.mathworks.cn/matlabcentral/profile/authors/5980614tag:ww2.mathworks.cn,2005:Question/3494422017-07-19T14:55:44Z2021-05-13T04:15:49ZHow to solve the 'StopFcn' error when the cause is "Vectors must be the same length."I have got a simulation file for a grid-tie inverter, which I am going to leave its image below. When I run the simulation, I receive the following error:
Error evaluating 'StopFcn' callback of block_diagram 'DC2ACGRID2'.
Caused by:
Vectors must be the same length.
I cannot figure out what vectors are causing this trouble. Any help is very much appreciated.
<</matlabcentral/answers/uploaded_files/83337/error-pic.png>>
sara yazdanihttps://ww2.mathworks.cn/matlabcentral/profile/authors/8614879tag:ww2.mathworks.cn,2005:Question/1971182015-04-10T13:47:52Z2021-05-13T04:13:28ZHow can I get rid of this error? Please help me guysE = 10e7; poisson = 0.30;
C=E/(1-poisson^2)*[1 poisson 0;poisson 1 0;0 0 (1-poisson)/2];
P = 1e6;
Lx=5; Ly=1;
numberElementsX=20;
numberElementsY=10;
numberElements=numberElementsX*numberElementsY;
[nodeCoordinates, elementNodes] =rectangularMesh(Lx,Ly,numberElementsX,numberElementsY);
xx=nodeCoordinates(:,1);
yy=nodeCoordinates(:,2);
drawingMesh(nodeCoordinates,elementNodes,'Q4','k-');
numberNodes=size(xx,1);
GDof=2*numberNodes;
stiffness=formStiffness2D(GDof,numberElements,elementNodes,numberNodes,nodeCoordinates,C,1,1); % boundary conditions
fixedNodeX=find(nodeCoordinates(:,1)==0);
fixedNodeY=find(nodeCoordinates(:,1)==0); % fixed in YY
prescribedDof=[fixedNodeX; fixedNodeY+numberNodes];
force=zeros(GDof,1);
rightBord=find(nodeCoordinates(:,1)==Lx);
force(rightBord+numberNodes)=P*Ly/numberElementsY;
force(rightBord(1)+numberNodes)=P*Ly/numberElementsY/2;
force(rightBord(end)+numberNodes)=P*Ly/numberElementsY/2;
displacements=solution(GDof,prescribedDof,stiffness,force);
% displacements and deformed shape
disp('Displacements')
jj=1:GDof; format f=[jj; displacements'];
fprintf('node U\n') fprintf('%3d %12.8f\n',f)
UX=displacements(1:numberNodes); UY=displacements(numberNodes+1:GDof);
scaleFactor=0.1; figure
drawingField(nodeCoordinates+scaleFactor*[UX UY],elementNodes,'Q4',UX);%U XX hold on
drawingMesh(nodeCoordinates+scaleFactor*[UX UY],elementNodes,'Q4','k-');
drawingMesh(nodeCoordinates,elementNodes,'Q4','k--');
colorbar
title('U XX (on deformed shape)')
axis off
% stresses at nodes stresses2D(GDof,numberElements,elementNodes,numberNodes,nodeCoordinates,displacements,UX,UY,C,scaleFactor);
''Undefined function or variable "nodeCoordinates".''
[nodeCoordinates, elementNodes] =rectangularMesh(Lx,Ly,numberElementsX,numberElementsY);Nahidhttps://ww2.mathworks.cn/matlabcentral/profile/authors/6292913tag:ww2.mathworks.cn,2005:Question/5077902020-02-26T23:55:23Z2021-05-13T04:09:37ZSimulink data inspector missing some logged signalsSimulink data inspector suddenly stopped logging some, but not all signals in my model. I can't think of any changes I would have made to the model that would have caused this. It seems that the data inspector is struggling to communicate with the model. I can stop logging signals that are currently working with the data inspector, but cannot start logging them again. I recently updated to matlab 2019b.
I've tried running >> sdi.Repository.clearRepositoryFile
Any help would be appreciated. Thanks in advance.
Michael McGeehanhttps://ww2.mathworks.cn/matlabcentral/profile/authors/6038798tag:ww2.mathworks.cn,2005:Question/4567602019-04-16T19:05:53Z2021-05-13T04:09:33ZMethod to find singularity We are writing a program for linear function, in particolare we are writing code for a functio to find the singularity in a matrix.
We are asking in This function is right:
A method to find the singularity without the deterimnant wuold be to verify the number of element not null in the Matrix in particular, in the number of elements not null is lower thai one of the 2 dimensioni of the Matrix then the Matrix will be singular valerio auricchiohttps://ww2.mathworks.cn/matlabcentral/profile/authors/9866112tag:ww2.mathworks.cn,2005:Question/8289582021-05-13T03:59:15Z2021-05-13T03:59:15ZHow can I export the picture to matrixNow I have a 3D result picture from comsol. I want to transform this picture to Three-dimensional matrix in order to analysis electric field distribution.What should I do or what code should I enter in matlab.I'm waiting for someone who can solve this problem.Thanks for your attention.远志 崔https://ww2.mathworks.cn/matlabcentral/profile/authors/22327069tag:ww2.mathworks.cn,2005:Question/8282302021-05-12T11:20:45Z2021-05-13T03:49:39ZHow to remove awgn from and ecg signal?I'am doing this project on removing both PLI and AWGN in the ecg. I have downloaded the ecg code for generating the signal from matlab. I tried using Chebyshev2 and the Wiener filter to filter out the two noises. But that makes it even worse. Please to help me .I'll provide my code :
Fs = 1000;
Ts = 1/Fs;
x=0:Ts:10-Ts;
li=30/72;
a_pwav=0.25;
d_pwav=0.09;
t_pwav=0.16;
a_qwav=0.025;
d_qwav=0.066;
t_qwav=0.166;
a_qrswav=1.6;
d_qrswav=0.11;
a_swav=0.25;
d_swav=0.066;
t_swav=0.09;
a_twav=0.35;
d_twav=0.142;
t_twav=0.2;
a_uwav=0.035;
d_uwav=0.0476;
t_uwav=0.433;
pwav=p_wav(x,a_pwav,d_pwav,t_pwav,li);
%qwav output
qwav=q_wav(x,a_qwav,d_qwav,t_qwav,li);
%qrswav output
qrswav=qrs_wav(x,a_qrswav,d_qrswav,li);
%swav output
swav=s_wav(x,a_swav,d_swav,t_swav,li);
%twav output
twav=t_wav(x,a_twav,d_twav,t_twav,li);
%uwav output
uwav=u_wav(x,a_uwav,d_uwav,t_uwav,li);
%ecg output
ecg=pwav+qrswav+twav+swav+qwav+uwav;
figure(1)
plot(x,ecg);
xlabel('Time[s]')
ylabel('Amplitude')
title('ECG')
%pli
fNoise = 50; % Frequency [Hz]
aNoise = 1; % Amplitude
noise = aNoise*sin(2*pi.*x.*fNoise);
pliecg=ecg + noise;
%adding awgn
SNR=0;
noisy = awgn(pliecg,SNR,'measured')
figure(2)
plot(x,noisy)
xlabel('Time[s]')
ylabel('Amplitude')
title('Noisy')
function [pwav]=p_wav(x,a_pwav,d_pwav,t_pwav,li)
l=li;
a=a_pwav;
x=x+t_pwav;
b=(2*l)/d_pwav;
n=100;
p1=1/l;
p2=0;
for i = 1:n
harmonic1=(((sin((pi/(2*b))*(b-(2*i))))/(b-(2*i))+(sin((pi/(2*b))*(b+(2*i))))/(b+(2*i)))*(2/pi))*cos((i*pi*x)/l);
p2=p2+harmonic1;
end
pwav1=p1+p2;
pwav=a*pwav1;
end
function [qrswav]=qrs_wav(x,a_qrswav,d_qrswav,li)
l=li;
a=a_qrswav;
b=(2*l)/d_qrswav;
n=100;
qrs1=(a/(2*b))*(2-b);
qrs2=0;
for i = 1:n
harm=(((2*b*a)/(i*i*pi*pi))*(1-cos((i*pi)/b)))*cos((i*pi*x)/l);
qrs2=qrs2+harm;
end
qrswav=qrs1+qrs2;
end
function [qwav]=q_wav(x,a_qwav,d_qwav,t_qwav,li)
l=li;
x=x+t_qwav;
a=a_qwav;
b=(2*l)/d_qwav;
n=100;
q1=(a/(2*b))*(2-b);
q2=0;
for i = 1:n
harm5=(((2*b*a)/(i*i*pi*pi))*(1-cos((i*pi)/b)))*cos((i*pi*x)/l);
q2=q2+harm5;
end
qwav=-1*(q1+q2);
end
function [swav]=s_wav(x,a_swav,d_swav,t_swav,li)
l=li;
x=x-t_swav;
a=a_swav;
b=(2*l)/d_swav;
n=100;
s1=(a/(2*b))*(2-b);
s2=0;
for i = 1:n
harm3=(((2*b*a)/(i*i*pi*pi))*(1-cos((i*pi)/b)))*cos((i*pi*x)/l);
s2=s2+harm3;
end
swav=-1*(s1+s2);
end
function [twav]=t_wav(x,a_twav,d_twav,t_twav,li)
l=li;
a=a_twav;
x=x-t_twav-0.045;
b=(2*l)/d_twav;
n=100;
t1=1/l;
t2=0;
for i = 1:n
harm2=(((sin((pi/(2*b))*(b-(2*i))))/(b-(2*i))+(sin((pi/(2*b))*(b+(2*i))))/(b+(2*i)))*(2/pi))*cos((i*pi*x)/l);
t2=t2+harm2;
end
twav1=t1+t2;
twav=a*twav1;
end
function [uwav]=u_wav(x,a_uwav,d_uwav,t_uwav,li)
l=li;
a=a_uwav
x=x-t_uwav;
b=(2*l)/d_uwav;
n=100;
u1=1/l
u2=0
for i = 1:n
harm4=(((sin((pi/(2*b))*(b-(2*i))))/(b-(2*i))+(sin((pi/(2*b))*(b+(2*i))))/(b+(2*i)))*(2/pi))*cos((i*pi*x)/l);
u2=u2+harm4;
end
uwav1=u1+u2;
uwav=a*uwav1;
end
v shikhashastrihttps://ww2.mathworks.cn/matlabcentral/profile/authors/13206832tag:ww2.mathworks.cn,2005:Question/7124032021-01-09T06:09:16Z2021-05-13T03:44:16ZHow to convert this simulink model to VHDL ?I have simulated a sinusoidal wave using the SIMULINK by using an integrator,gain and constant. I tried to convert this to VHDL but not able to do so.
This is the SIMULINK model which I simulated in SIMULINK which I got a sinusoidal output. I want to know what are the necessary changes which I have to do in order to get a VHDL code for the same?
Jerry Jacobhttps://ww2.mathworks.cn/matlabcentral/profile/authors/18942340tag:ww2.mathworks.cn,2005:Question/8289532021-05-13T03:27:29Z2021-05-13T03:36:39ZI need to create two test and train folder from one parent folder (in the same directory), I wrote the code, but file couldn't be moved. Please Help!!files = dir('*.jpg');
N=numel(files);
tf = randperm(N) > (0.80 *N);
TF=tf';
mkdir Test
mkdir Train
for i=1:1:N
filename = files(i).name;
A = imread(filename);
image=imshow(A);
if TF(i)==1
movefile(image, Train)
else
movefile(image, Test)
end
endPriyom Goswamihttps://ww2.mathworks.cn/matlabcentral/profile/authors/22508631tag:ww2.mathworks.cn,2005:Question/8025212021-04-14T22:29:27Z2021-05-13T03:15:33ZProbability vector from a Markov Transition Matrix Can somebody tell me how to calculate the probability matrix from a Markov Transition Matrix which values are known? I'm not familiar with this calulations in Matlab.
This is the Markov Transition Matrix:
Note: All transition rates of the matrix are known values except for the variable "θpm"
Which script lines should I enter into Matlab to find the values of the P vector for a given "θpm"? And how can I plot a graphic "AbUn" vs. "θpm"? knowing that AbUn=P4+P8 and "P4" and P8" are variables from the probability vector (P).
Thanks a lot in advanceDaniel Caballerohttps://ww2.mathworks.cn/matlabcentral/profile/authors/18291999tag:ww2.mathworks.cn,2005:Question/8289382021-05-13T03:06:43Z2021-05-13T03:06:43ZThe measurement of sensor of weld Joint in simscape of simulink is discontinuous
As show in the picture, the curve are sensor data of weld joint in simscape of simulink. I let two objects touch continuously in simulink, but the data is not continuous.Is this related to the simulation step size or consistency tolerance I set? I have tried to set them small, but that doesn't work. Please help me to solve this problem. Further more, I found other Joint's sensor in simscape also have this problem, eg. 6-DOF Joint.QingShan Zenghttps://ww2.mathworks.cn/matlabcentral/profile/authors/16675313tag:ww2.mathworks.cn,2005:Question/8289032021-05-13T01:47:04Z2021-05-13T03:05:17ZUse data in an array for 'Plot' commandI need to draw a shape using the 'Plot' command, the data is stored in an array called 'shape'. This is my attempt so far:
for i=1:1:length(shape(j,4,i))-1
plot([shape(j,4,i) shape(j,4,i+1)],[shape(j,5,i) shape(j,5,i+1)],'k');
hold on;
end
plot([shape(j,4,i))(length(shape(j,4,i)) shape(j,4,i)(1)],[shape(j,5,i)(length(shape(j,5,i))) shape(j,5,i)(1)],'k');
end
I receive this error: "Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters."
Is this the correct format to use to call data from an array because I cannot see any problems with the brackets?
Thank youLRhttps://ww2.mathworks.cn/matlabcentral/profile/authors/21387466tag:ww2.mathworks.cn,2005:Question/8289332021-05-13T03:02:16Z2021-05-13T03:02:16ZHow to change the message sending period of the Simulink "CAN Trasmit" block to a value less than 5ms?One of the parameters of the Simulink "CAN Transmit" block is the message period. I try to change it to less than 5ms and say I can't change it, however, when it comes to communication, 5ms is a relatively high value. How do I modify it?Gaspar Oliveirahttps://ww2.mathworks.cn/matlabcentral/profile/authors/17795922tag:ww2.mathworks.cn,2005:Question/8289132021-05-13T02:01:47Z2021-05-13T02:57:04ZFrom a matrix how can I randomly select one column combination at a timeSuppose I have
A = [ 1 0 0
0 1 1
1 1 0]
I would like to get any column based on value of a random number, and send to another matrix with the other two columns successively.Neetha Francishttps://ww2.mathworks.cn/matlabcentral/profile/authors/12645151tag:ww2.mathworks.cn,2005:Question/3071642016-10-13T04:00:00Z2021-05-13T02:52:08ZWhy do I receive an Error regarding third party software when Downloading or Installing a support package?Why do I get an Error regarding third party software when Downloading or Installing a support package?
eg: Failed to install third party packagesMathWorks Support Teamhttps://ww2.mathworks.cn/matlabcentral/profile/authors/4622813tag:ww2.mathworks.cn,2005:Question/8289282021-05-13T02:40:59Z2021-05-13T02:40:59ZSome of my test sequence files are not openingSome of my test sequence files are not opening. An empty window pops up and it shows nothing. What could be the reason.Arockia Arun Prasad Jesurethinamhttps://ww2.mathworks.cn/matlabcentral/profile/authors/18255425tag:ww2.mathworks.cn,2005:Question/8205502021-05-03T15:10:31Z2021-05-13T02:34:48ZDecision Feedback Equalizer Crashes Matlab with InputSamplesPerSymbol optionI make use of Decision Feedback Equalizer from Communications Toolbox with PAM-2 (OOK) signal. In my setup each symbol has 10 samples and I used "InputSamplesPerSymbol" parameter in the equalizer initializaiton.
DFE compiles succesfully however when I call the DFE with data, MATLAB crashes without any warnings/errors/output.
I have tried this on another setup as well and the result is no different. What can be a potential cause and what would be a possible workaround or a solution?
%% Generate Samples
numTrainSymbols = 200;
numDataSymbols = 1800;
numSamples = 10;
trainingSymbols = real(pammod(randi([0 1],numTrainSymbols,1),2));
dataSymbols = real(pammod(randi([0 1],numDataSymbols,1),2));
stream = repelem([trainingSymbols; dataSymbols], numSamples);
SNR = 20;
ch_out = awgn(stream, 20);
%% Input Data
dfeq = comm.DecisionFeedbackEqualizer('Algorithm','LMS', ...
'NumForwardTaps',5,...
'NumFeedbackTaps',4,...
'ReferenceTap',5,...
"Constellation", [-1 1], ...
'StepSize',0.001, ...
"InputSamplesPerSymbol", numSamples);
[y, err, weights] = dfeq(ch_out, trainingSymbols);Arda Karacahttps://ww2.mathworks.cn/matlabcentral/profile/authors/13652486