https://kr.mathworks.com/matlabcentral/answers/questionsMATLAB Answers — 새 질문2021-06-15T04:29:16Ztag:kr.mathworks.com,2005:Question/8563852021-06-15T02:50:46Z2021-06-15T04:29:16ZUnderstanding the difference between ndgrid and meshgrid (from Numpy)Hello everyone,
I am just trying to understand a diffrance between ngrid. Please observe the code below when I check the size of the Ngrid2 I get two cells of $10 \times 10$ and three cells of 15 15 15, but when I do something similar in numpy meshgrid function I get . Can someone please explain to me the diffrance? Also please advise if there is any way to make Matlab ngrid behave as meshgrid from numpy.
Thank you very much in advance for the consideration!
%Matlab
x = linspace(0,1,5);
[Ngrid2{:}] = ndgrid(x,x);
[Ngrid3{:}] = ndgrid(x,x);
%Python Numpy
x = np.linspace(0,1,5)
z = np.array(np.meshgrid(x,x))
Radoslav Vuchkovhttps://kr.mathworks.com/matlabcentral/profile/authors/8815310tag:kr.mathworks.com,2005:Question/8556702021-06-14T09:18:13Z2021-06-15T04:28:50ZOpen and procces multiple imagesHey everyone, I have a 870 images from 29 different classes and each class has 30 images in sequential number from 1 to 30, following this pattern NameOfTheImage_1-30. What I want to do is to open and then convert all of the images, automatically one by one, into grayscale. Can you help me with that? The codes from here are somehow usefull but not for my case (I think).Pavel Todorovhttps://kr.mathworks.com/matlabcentral/profile/authors/12883689tag:kr.mathworks.com,2005:Question/836252013-07-31T10:56:35Z2021-06-15T04:28:10Z3D -3D rigid body image registrationHi everyone
I know Matlab can perform intensity based 2d image registration; But is it capable of 3D-3D image registration? Lets say between two .STL files?
Please give your thoughts
JolantaJolanta Gavrowskihttps://kr.mathworks.com/matlabcentral/profile/authors/3366852tag:kr.mathworks.com,2005:Question/8563152021-06-14T23:42:20Z2021-06-15T04:24:46ZHow to create concentric circles?Hello, I want to generate a series of concentric circles by filling each ring with a different color. The result I want to obtain is similar to the figure. With the code I present, I get the figure 2. How could I assign a color to each ring between the circles?
Thanks in advance
clear;
clc;
close all
x_center = 0;
y_center = 0;
pellet = 0.3355;
gap = 0.350;
w14re = 0.354;
re = 0.355;
clad = 0.455;
sicfib = 0.458;
radius_array = [pellet gap w14re re clad sicfib];
for i = 1:5
radius = 5;
theta = 0:pi/50:2*pi;
x_circle_1 = radius_array(i) * cos(theta) + x_center;
y_circle_1 = radius_array(i) * sin(theta) + y_center;
x_circle_2 = radius_array(i+1) * cos(theta) + x_center;
y_circle_2 = radius_array(i+1) * sin(theta) + y_center;
fig1 = plot(x_circle_1, y_circle_1, 'k-', 'LineWidth', 0.5);
hold on
fig2 = plot(x_circle_2, y_circle_2, 'k-', 'LineWidth', 0.5);
hold on
axis equal
axis off
end
Yrohttps://kr.mathworks.com/matlabcentral/profile/authors/15569337tag:kr.mathworks.com,2005:Question/8564252021-06-15T04:24:43Z2021-06-15T04:24:43ZUpload data to Thingspeak using a Arduino MKR NB1500Is there a basic starter example of using an Arduino MKR NB1500 to upload sensor data over the mobile phone network to a Thingspeak channel?
NB M1 cell networks are being deployed by Telcos, the Arduino NB1500 is available.Barnard Richardshttps://kr.mathworks.com/matlabcentral/profile/authors/10576216tag:kr.mathworks.com,2005:Question/8564102021-06-15T03:59:36Z2021-06-15T04:19:15ZDefine time interval for wave of highest peakAlong with greeting, I attach 2 .txt files, one for amplitudes and the other for flow, which are 1441x50, where each column represents different simulations and the rows are the variation of the parameter (both amplitude and flow) as a function of time (for that I define a time vector). The problem I have is how to define both for the case of amplitude and flow, the time interval (x axis), where the maximum peak is found but considering the entire wave of said peak, and unfortunately all the scenarios are very different, then I wanted to ask for help to define some criteria or method to get the time range.
I present two figures that show in a schematic way what I need (I did it visually by seeing the maximum peak and defined the interval by seeing the wave that contained it), but I need it in numerical form, I mean to quantify that interval, and define a criterion to be able to perform it for all simulations, in total there are 50 simulations.
In red vertical lines I defined an interval considering the wave where the peak value is, but it was done by eye, so I need your help to be able to do it automatically with matlab and defining a criterion to be able to do it, since as I mentioned earlier the simulations are very different.
Thanks greetings.
close all, clear all, clc
load 'flow.txt' % amplitude vector is defined in meters
load 'amplitude.txt' % the flow vector is defined in (m^3/s)
t=(0:10:4*3600)'; % is a time vector every 10 seconds in a total of 4 hours
figure, plot(t,amplitude(:,1)) , ylabel('Amplitude (m)') , xlabel('Time (s)')
figure, plot(t,flow(:,1)) , ylabel('Flow (m^3/s)') , xlabel('Time (s)')
ignacio bobadilla tapiahttps://kr.mathworks.com/matlabcentral/profile/authors/6966300tag:kr.mathworks.com,2005:Question/8564202021-06-15T04:07:52Z2021-06-15T04:18:01ZImaginary parts of complex X and/or Y arguments ignored> %computation of lambda - i curve
clear all
close all
%assign parameters
cm = 1e-2;
mm = 1e-2;
w=1*cm; %core width
Ws=5*cm; %slot width
ds=2*cm; %slot depth
d=5*cm; %depth
g=1*mm; %air gap
N=100; %number of turns
muo=4e-7*pi; %perm of free space
Bsat=1.3; %sat flux density
mur=1500; %init rel permeability
Am=w*d; %mag cross section
%start with flux linkage
lambda= linspace(0,0.08,1000);
%find flux, B, mu
phi=lambda/N;
B=phi/(w*d);
mu= muo *(mur-1)./(exp(10*(B-Bsat)).^2+1)+ muo;
%assign reluctance
Ric=(Ws+w)./(Am*mu);
Rbuc=(Ws+w)./(Am*mu);
Rg=g/(Am*muo);
Rluc= (ds+w/2)./(Am*mu);
%compute effective reluctance
Reff= Ric+Rbuc+2*Rg+2*Rluc;
%compute mmf and current
F=Reff.*phi;;
%find the characteristics
figure(1)
plot(i, lambda);
xlabel ('i,A');
ylabel ('\lambda, Vs');
grid on;
%show B-H characteristics
H=B/mu;
figure (2)
plot (H,B);
xlabel('H')
ylabel('B')
grid on;
Warning: Imaginary parts of complex X and/or Y arguments ignored.
it shows me this warning, also shows me empty figures.sara07x xhttps://kr.mathworks.com/matlabcentral/profile/authors/12144935tag:kr.mathworks.com,2005:Question/8564152021-06-15T04:04:59Z2021-06-15T04:15:27ZI am trying to code the inverse power method but the outcome of the eigenvector was half of the correct answer. Is there a way to fix it?clc,clear
format long
A = input('Please enter square matrix A: ');
u = input('Please enter initial guess vector u: ');
s = input('Please enter max number of steps s: ');
[row,column] = size(A);
I = 1;
k = 0;
while I <= column
if u(I) == 0
I = I+1;
elseif u(I) ~= 0
y = sign(u(I))*(u/norm(u));
I = 1;
break
end
end
while k <= s-1
t = rref([A,y]);
z = t(:,row+1);
while I <= column
if y(I)==0 & z(I)==0
I = I+1;
elseif y(I)~=0 & z(I)== 0
I = I+1;
elseif y(I)==0 & z(I)~=0
I = I+1;
elseif y(I)~= 0 & z(I)~=0
p = y(I)/z(I);
sig = sign(z(I));
y = sig*(z/norm(z));
k = k+1;
break
end
end
end
fprintf('The approximation for the eigenvalue of A with smallest absolute value is: %s\n',p)
fprintf('The approximation for the eigenvector of A with smallest absolute value is:\n')
fprintf(' %d\n',[y])
Here is the example for the code:
%The matrix of A is:
[4 1 0; 1 4 1; 0 1 4]
%The initial vector is:
[0.05346163504453; 0.52970019333516; 0.67114938407724]
%The number of steps is:
1000
%The supposed answer is:
[1; -sqrt(2); 1]
%The answer I got from the code is:
[0.5; -sqrt(2)/2; 0.5]Kien Nguyenhttps://kr.mathworks.com/matlabcentral/profile/authors/22741521tag:kr.mathworks.com,2005:Question/8346532021-05-20T01:59:50Z2021-06-15T04:13:26ZCan I use Antenna Toolbox to model antenna near metal structureHi,
I want to model the radiation pattern, impedance, etc of an antenna (e.g. a dipole) near a custom metal structure. I don't see how to do this in Antenna Toolbox.
Similarly, how do I model a monopole on a circular groundplane inside a metal tube?
Thanks,
MarcoMarcohttps://kr.mathworks.com/matlabcentral/profile/authors/4058869tag:kr.mathworks.com,2005:Question/8538402021-06-11T12:19:35Z2021-06-15T03:57:05ZHow to find area under graph between two points ?I used this coding but i dont know how to set the specific points. I used array data.
M = area(A(:,1),A(:,2));
Int = trapz(A(:,1),A(:,2));
Mohamad Firdaus Bin Adnanhttps://kr.mathworks.com/matlabcentral/profile/authors/22111576tag:kr.mathworks.com,2005:Question/8564052021-06-15T03:49:01Z2021-06-15T03:57:02ZWhat is difference between corrcoef([A B]) and corrcoef(A, B)?Is there any output difference between both of them? Which format is advisable to use when we wish to find correlation between 2 matrices?Krtin Kalahttps://kr.mathworks.com/matlabcentral/profile/authors/20159300tag:kr.mathworks.com,2005:Question/8563552021-06-15T01:42:49Z2021-06-15T03:50:52ZFind only numeric strings on cellstr array. I'd like to know the index of the "numerical strings" within a cellstr array.
arr = {'123', 'Hola', 'my', 'String', '', '1453', 'stay'};
A correct output will give me index 1 and 6.
isnumeric contained within cellfun doesn't work well here, I'd have to use it in combination with something else but I don't know exactly what that might be.
Any help is appreciated.
Ajpaezmhttps://kr.mathworks.com/matlabcentral/profile/authors/6042318tag:kr.mathworks.com,2005:Question/8563952021-06-15T03:24:33Z2021-06-15T03:40:11ZDividing image into grid - imwrite breaks when processing an empty imageHello All,
Basically, I have a set of code that will split images into equal sized squares. At the end, the code names each square according to a grid pattern. (Letters on x-axis, numbers on y.) However, the imwrite function at the very end gives me the following error:
Error using imwrite (line 442)
Expected DATA to be nonempty.
Error in simultaneous (line 92)
imwrite(ca{r,c}, filename);
I know this is because it tried to create a column where none of the picture exists. In my most recent attempt, I set the numbers so that the original picture would split into a 2x2 grid. However, the program tried to create a 3rd column, column AC, and subsequently tried to generate image AC_001. Since AC_001 was empty, the program broke.
Does anyone have a solution to stop my code from breaking?
Full code is attached below, the problem area is at the very bottom.
Thank you!
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
workspace; % Make sure the workspace panel is showing.
fontSize = 20;
% Read in a standard MATLAB color demo image.
folder = fullfile(matlabroot, '\toolbox\images\imdata');
baseFileName = 'cameraman.tif';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, 'file')
% Didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
% Read the image from disk.
rgbImage = imread(fullFileName);
% Display image full screen.
imshow(rgbImage);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
drawnow;
% Get the dimensions of the image. numberOfColorBands should be = 3.
[rows columns numberOfColorBands] = size(rgbImage)
% The first way to divide an image up into blocks is by using mat2cell().
blockSizeR = 128; % Rows in block.
blockSizeC = 128; % Columns in block.
% Figure out the size of each block in rows.
% Most will be blockSizeR but there may be a remainder amount of less than that.
wholeBlockRows = floor(rows / blockSizeR);
blockVectorR = [blockSizeR * ones(1, wholeBlockRows), rem(rows, blockSizeR)];
% Figure out the size of each block in columns.
wholeBlockCols = floor(columns / blockSizeC);
blockVectorC = [blockSizeC * ones(1, wholeBlockCols), rem(columns, blockSizeC)];
% Create the cell array, ca.
% Each cell (except for the remainder cells at the end of the image)
% in the array contains a blockSizeR by blockSizeC by 3 color array.
% This line is where the image is actually divided up into blocks.
if numberOfColorBands > 1
% It's a color image.
ca = mat2cell(rgbImage, blockVectorR, blockVectorC, numberOfColorBands);
else
ca = mat2cell(rgbImage, blockVectorR, blockVectorC);
end
% Now display all the blocks.
plotIndex = 1;
numPlotsR = size(ca, 1);
numPlotsC = size(ca, 2);
for r = 1 : numPlotsR
for c = 1 : numPlotsC
fprintf('plotindex = %d, c=%d, r=%d\n', plotIndex, c, r);
% Specify the location for display of the image.
subplot(numPlotsR, numPlotsC, plotIndex);
% Extract the numerical array out of the cell
% just for tutorial purposes.
rgbBlock = ca{r,c};
imshow(rgbBlock); % Could call imshow(ca{r,c}) if you wanted to.
[rowsB columnsB numberOfColorBandsB] = size(rgbBlock);
% Make the caption the block number.
drawnow;
% Increment the subplot to the next location.
plotIndex = plotIndex + 1;
end
end
% Display the original image in the upper left.
subplot(4, 6, 1);
imshow(rgbImage);
title('Original Image');
for r = 1 : numPlotsR
for c = 1 : numPlotsC
filename = sprintf('%s_%03d.png',append(char(idivide(c,int32(26),"floor")+65),char(mod(c,26)+64)), r)
imwrite(ca{r,c}, filename);
end
end
David Bukowskihttps://kr.mathworks.com/matlabcentral/profile/authors/18666121tag:kr.mathworks.com,2005:Question/8564002021-06-15T03:33:56Z2021-06-15T03:33:56ZHow to extract best features using MRMR function?I extracted features using wavelet scattering that is for each time series (36 x 361) features. my response is either 0 or 1 for each cell. I am trying to use the MRMR function to select the best features among the 361 features.
A screenshot of the data is attached.
Arif Hussainhttps://kr.mathworks.com/matlabcentral/profile/authors/15716671tag:kr.mathworks.com,2005:Question/8436802021-05-30T14:55:49Z2021-06-15T03:32:42ZDisplay data of a particular variable present in a netcdf fileHello people!
I am a newbie in MATLAB who has just started to use for the past month or so am facing issue while learning to work with oceanic netcdf files for my project purpose.
I have a netcdf file as an output from my oceanographic simulation and I want to get a single ouput for a particular variable from my output file for a specific latitude longitude, time index and depth.
eg: I want to get the value of u momentum velocity from the variable u for latitude "-8.22426367031282" and longitude "115.309657931722" , level index = 1 (for my s_rho value) , and a specific oceantime say " 01-Apr-2008-15:00:00" or any such timestep, when I input all these values say u_vel[115.309657931722 ,-8.22426367031282, 1 , '01-Apr-2008-15:00:00'] , I hope to get an ouput like 0.25477523 (any units).
Here are my dimension of the output file and the variable:
Output file: Dimensions:
xi_rho = 100
xi_u = 99
xi_v = 100
xi_psi = 99
eta_rho = 50
eta_u = 50
eta_v = 49
eta_psi = 49
N = 15
s_rho = 15
s_w = 16
tracer = 1
boundary = 4
ocean_time = 7 (UNLIMITED)
u
Size: 99x50x15x273
Dimensions: xi_u,eta_u,s_rho,ocean_time
Datatype: single
Attributes:
long_name = 'u-momentum component'
units = 'meter second-1'
time = 'ocean_time'
grid = 'grid'
location = 'edge1'
coordinates = 'lon_u lat_u s_rho ocean_time'
v
Size: 100x49x15x7
Dimensions: xi_v,eta_v,s_rho,ocean_time
Datatype: single
Attributes:
long_name = 'v-momentum component'
units = 'meter second-1'
time = 'ocean_time'
grid = 'grid'
location = 'edge2'
coordinates = 'lon_v lat_v s_rho ocean_time'
field = 'v-velocity, scalar, series'
I wrote a code for an attempt but every time I execute my MATLAB crashes and also I am not sure if what I am doing will give me any result as well: If anybody please suggest me the right script for my intended job, that would be of great great help.
file = 'Lombok_roms_his.nc';
latitude = ncread(file,'lat_u');
longitude = ncread(file,'lon_u');
mask = ncread(file,'mask_rho');
time = ncread(file,'ocean_time');
u_vel = ncread(file,'u');
v_vel = ncread(file,'v');
%% this is the part which I try to exceute in command window%%
u_vel[115.309657931722 ,-8.22426367031282, 1 , '01-Apr-2008-15:00:00']
v_vel[115.309657931722 ,-8.22426367031282, 1 , '01-Apr-2008-15:00:00']Shankhaneel Basakhttps://kr.mathworks.com/matlabcentral/profile/authors/16451181tag:kr.mathworks.com,2005:Question/8563902021-06-15T03:23:57Z2021-06-15T03:23:57ZUsing structfun with wcoherence functionI am attempting to calculate coherence for waveform data. There are a total of 44 channels. The usual way of processing is to go through a for loop (as shown below)
df = rand(8902,44); % create the array
fs = 5; % sample rate is 5Hz
[wcoh1,wcs1,f1,coi1] = wcoherence(df(:,1),df(:,2),fs);
In order to speed up the processing, I am trying to use structfun and gpuArray to run through all possible iterations. I have been able to calculate the mean using structfun but have been unable to use wcoherence. Below is my attempt
df = rand(8902,44); % create the array
df_gpu = gpuArray(df) % convert to GPU array
fs = 5; % sample rate is 5Hz
combinations = nchoosek(uint16([1:44]),uint16(2)); % gives me all the unique combinations of coherence
[wcoh1,wcs1,f1,coi1] = wcoherence(df_gpu(:,1),df_gpu(:,2),fs);
Does anyone have any recommendations on using combinations to index df_gpu and then compute the coherence?
Thanks for any insight.
Patrickhttps://kr.mathworks.com/matlabcentral/profile/authors/7140704tag:kr.mathworks.com,2005:Question/8562602021-06-14T22:01:36Z2021-06-15T03:22:14ZBoundary Value Problem\ Symbolic solutionI wanted to solve a sturm-liouville boundary value problem using the symbolic command dsolve, and I wanted to avoid using character vectors input as MATLAB suggests. but this wrong asnwer apears when using the classical symbolic way:
Sara Slamehhttps://kr.mathworks.com/matlabcentral/profile/authors/18376566tag:kr.mathworks.com,2005:Question/8563402021-06-15T01:14:01Z2021-06-15T03:16:18ZError using <= Not enough input argumentsThis is my matlab code, it shows me error.
%computation of lambda - i curve
clear all
close all
%assign parameters
cm = 1e-2;
mm = 1e-2;
w=1*cm; %core width
Ws=5*cm; %slot width
ds=2*cm; %slot depth
d=5*cm; %depth
g=1*mm; %air gap
N=100; %number of turns
muo=4e-7*pi; %perm of free space
Bsat=1.3; %sat flux density
mur=1500; %init rel permeability
Am=w*d; %mag cross section
%start with flux linkage
lambda= linspace(0,0.08,1000);
%find flux, B, mu
phi=lambda/N;
B=phi/(w*d);
mu= muo *(mur-1)./(exp(10*(B-Bsat)).^2+1)+ muo;
%assign reluctance
Ric=(Ws+w)./(Am*mu);
Rbuc=(Ws+w)./(Am*mu);
Rg=g/(Am*muo);
Rluc= (ds+w/2)./(Am*mu);
%compute effective reluctance
Reff= Ric+Rbuc+2*Rg+2*Rluc;
%compute mmf and current
F=Reff.kphi;;
%find the characteristics
figure(1)
plot(i, lambda);
xlabel ('i,A');
ylabel ('\lambda, Vs');
grid on;
%show B-H characteristics
H=B/mu;
figure (2)
plot (H,B);
xlabel('H')
ylabel('B')
grid on;
Dot indexing is not supported for variables of this type.
I corrected it but still shows me :Dot indexing is not supported for variables of this type.sara07x xhttps://kr.mathworks.com/matlabcentral/profile/authors/12144935tag:kr.mathworks.com,2005:Question/3132982016-11-21T05:00:00Z2021-06-15T03:14:40ZI already have MinGW on my computer. How do I configure it to work with MATLAB?I already have MinGW on my computer. How do I configure it to work with MATLAB?
MathWorks Support Teamhttps://kr.mathworks.com/matlabcentral/profile/authors/4622813tag:kr.mathworks.com,2005:Question/8554552021-06-14T04:26:19Z2021-06-15T03:06:57ZIs there a method to use ‘findpeaks’ to detect bright spots in an otherwise darkimage?I am currently having the problem that if I run findpeaks along the columns of said image, the same spot is being detected multiple times, as it appears as peak in every column.
I am aware that there are ad-on options for 2D peak detection, but I was hoping for a solution using findpeaks.
ヨナ エマヤhttps://kr.mathworks.com/matlabcentral/profile/authors/20993303tag:kr.mathworks.com,2005:Question/8557152021-06-14T10:08:55Z2021-06-15T02:58:49ZRoot locus imaginary axis intersectionOther than using interactive data cursors, is there anyway of finding the point where the root locus intersects the imaginary axis? Ande Mandoyihttps://kr.mathworks.com/matlabcentral/profile/authors/10661014tag:kr.mathworks.com,2005:Question/8563802021-06-15T02:50:09Z2021-06-15T02:50:09ZManaging similar apps using inheritance?I need to make approx. 20 apps that share a base set of app designer components and code and then provide extra functionality for a specific purpose. For example: a set of data processing programs with the same base app structure but each customized for a certain experiment. Is there a way to do this using inheritance or similar that would allow changes to the base code to propagate to the children?
The best idea I have is to create a base app and copy/paste that as a starting point for the children. That works for creating the apps but maintaining them could be difficult because every change to the base functionality needs to be repeated for each child.
I haven't found any examples where one app inherited another to extend the functionality. App merging sounded like a possible compromise (by making it easy to merge changes into child apps) but this only works for white editable code blocks and would not handle any changes to UI components or gray code blocks:
Compare and merge apps
Derek Wolfehttps://kr.mathworks.com/matlabcentral/profile/authors/22838103tag:kr.mathworks.com,2005:Question/8563752021-06-15T02:37:58Z2021-06-15T02:49:43Zhow do i use matlab to simulate partial discharge denoising using Fast Fourier Transformpartial discharge denoising using Fast Fourier Transformho wai kenhttps://kr.mathworks.com/matlabcentral/profile/authors/22838085tag:kr.mathworks.com,2005:Question/8563602021-06-15T02:26:14Z2021-06-15T02:43:53ZHow can I make obsolete block work in new version Simulink？I have a NI PCI-6229,I want to make it working in MATLAB 2018b,but,MATLAB 2018b show 'Obsolete block'.zhisheng Donghttps://kr.mathworks.com/matlabcentral/profile/authors/9402734tag:kr.mathworks.com,2005:Question/8562252021-06-14T20:46:34Z2021-06-15T02:43:38Zplot and left axis offWhen I plot it comes with both axes in the box. How can I plot by removing right axis (or vertical line) of Box? can you please help me?
x=(1:1:10);
y= (1:2:20);
figure (1);
plot (x,y,'o-');Babu Sankhihttps://kr.mathworks.com/matlabcentral/profile/authors/14694820tag:kr.mathworks.com,2005:Question/8563652021-06-15T02:32:47Z2021-06-15T02:37:24Zhow do i use matlab to simulate partial discharge denoising using Artificial Neural Networkpartial discharge denoisng using ANNho wai kenhttps://kr.mathworks.com/matlabcentral/profile/authors/22838085tag:kr.mathworks.com,2005:Question/8563702021-06-15T02:35:32Z2021-06-15T02:37:10Zhow do i use matlab to simulate partial discharge denoising using Discrere Wavelet Tranformpartial discharge denoising using Discrere Wavelet Tranformho wai kenhttps://kr.mathworks.com/matlabcentral/profile/authors/22838085tag:kr.mathworks.com,2005:Question/8563202021-06-14T23:53:57Z2021-06-15T02:36:42ZIn matlab app designer, how can we connect two or three app.mlapp?In matlab app designer, I have 2 app1.mlapp & app2.mlapp so how can I code this if I click one button in app1.mlapp then it will open the app2 .mlapp Sangeeta Sharmahttps://kr.mathworks.com/matlabcentral/profile/authors/21427471tag:kr.mathworks.com,2005:Question/8563452021-06-15T01:19:46Z2021-06-15T02:09:56ZCan someone explain this Code?Hi,
I have the following code on MATLAB, i don't know is it working properly or not. Would you help me to understand the complete content of code and how to make it work right?
clear, clc
for i=1:2:5
for j=1:2:5
x=x+3
xt=[xt x];
y=y+x
yt=[yt y];
end
endAhmet Burakhttps://kr.mathworks.com/matlabcentral/profile/authors/22837666tag:kr.mathworks.com,2005:Question/853632013-08-22T16:56:49Z2021-06-15T01:23:37ZWhich one is best for calculating circularity ? Hi all, I need to calculate objects roundness.I am not sure about which of the below ones is the best choice for this purpose.
- R= 4*pi*A/P^2; where A is area in pixels, P is Perimeter.
-Eccentricity
Thank you for your opinions.particles I need to measure are like this :
<<http://s21.postimg.org/nh0rzhhgn/den.png>>Muhammethttps://kr.mathworks.com/matlabcentral/profile/authors/3495067tag:kr.mathworks.com,2005:Question/8561302021-06-14T18:38:47Z2021-06-15T01:20:35ZIs there a way to access array elements returned by a function directlyAssume this code:
a=magic(4);
then I can do:
a(1,2)
to access the elements of the matrix a. Is there a way to do it directly without associating the variable a with the result of the function magic, that is, something like:
magic(4)(1,2)
?Leos Pohlhttps://kr.mathworks.com/matlabcentral/profile/authors/22640503tag:kr.mathworks.com,2005:Question/5004552020-01-15T16:28:50Z2021-06-15T01:19:12ZSingle Camera Calibration App: Checkerboard Corner Detection Stops mid wayI am using the Camera Calibration App for a computer vision research application. The camera images in IR and the checkerboard target is submerged in media (thus the pink color). The target is 10x10 mm with 0.2 mm squares from Edmund Optics. The problem is that the app detects corners only in half of the checkerboard. The target has an origin with two rectangles at 90 degrees that break the square pattern. It appears that this is what is throwing off the detection algo. Attached are some images for reference. If there is some way to ignore that center feature or get it to detect the entire pattern please share. Thank you in advance.
Nicholas Adams Castro Pricehttps://kr.mathworks.com/matlabcentral/profile/authors/9494075tag:kr.mathworks.com,2005:Question/8541602021-06-11T20:01:40Z2021-06-15T01:08:16ZHeun's method stiff ODE% solving the equation analyticaly
clear all
clc
s = dsolve('Dx = -2.3*x','x(0) = 1', 't');
sol = simplify(s)
% plot the analytical solution in the time interval
t0 = 0;
h = 0.01;
tend = 5;
t = [t0:h:tend];
sol = exp(-(2.3*t));
plot (t, sol, 'k-')
hold on;
% solving the equation numerically using explicit Euler's method
x0 = 1;
h1 = 1;
N = (tend - t0)/h1;
t = [t0:h1:tend];
x(1) = x0;
for i = 1:N
x(i+1) = x(i)+0.5*(h1*-2.3*x(i)+h1*-2.3*(h1*-2.3*x(i)));
end
plot(t,x,'o--')
title('Figure 3.5: Stiff ODE with Euler method when h = 1')
legend({'exact', 'Euler'},'location','southeast')
xlabel('t')
ylabel('x')
ax = gca;
ax.XTick = 0:1:5;
ax.XAxisLocation = 'origin';
ax.YAxisLocation = 'origin';
box off;
hold off;
Is there something wrong with my code??
As the correct graph is not showing.Aneesa Shahbazhttps://kr.mathworks.com/matlabcentral/profile/authors/17876664tag:kr.mathworks.com,2005:Question/8561252021-06-14T18:35:34Z2021-06-15T01:05:53ZHow to read multiple grb2 files on a webpage ?Dear all,
I like to download all the grb2 files from the following website:
https://polar.ncep.noaa.gov/waves/hindcasts/multi_1/200502/gribs
The file link can be identified, for instance, the first one is:
https://polar.ncep.noaa.gov/waves/hindcasts/multi_1/200502/gribs/multi_1.ak_4m.dp.200502.grb2
Is there a way to automatically update the link to download these files?
Thanks for the help.shukui liuhttps://kr.mathworks.com/matlabcentral/profile/authors/15034460tag:kr.mathworks.com,2005:Question/8557752021-06-14T11:11:25Z2021-06-15T01:05:48ZShape recognition from user input and obtain XYZ coordinatesI would like to identify the shape i need from the attached image according to the user input. After the shape has been recognised I want to be able to obtain the XYZ coordinates of the shape.
I thought it would be a simple use of the bwboundaries function or regionprops() but I can't seem to do so.
The attached images contains the shapes in white, so not including the black rectangle box that contains them.JamKonhttps://kr.mathworks.com/matlabcentral/profile/authors/18227683tag:kr.mathworks.com,2005:Question/2601722015-12-14T01:16:57Z2021-06-15T01:04:30ZPredict next value in a series using aryuleHello
I am trying to estimate what a value of the variable would be at time t+1 given we know the past values of the variable with 'aryule'. But i have problem using the function properly. Just as an example i am trying
x=[1 2 3 4 5 6 7 8 9 10 11 12];
p=12; %order of AR model
coeff=aryule(x,p);
nextValueX = -coeff(2:end) * x(end:-1:end-p+1)';
Please let me know if this seems right or do i need anything else?
Thanks
HarishHarish Palakurthihttps://kr.mathworks.com/matlabcentral/profile/authors/5979933tag:kr.mathworks.com,2005:Question/8563302021-06-15T00:46:21Z2021-06-15T01:01:08Zcalculating centroids of multiple ROIs at a timeHi,
I have segmented my ROIs, which are circles/ellipses. I need to calculate the centroids of all ROIs at a time and save those values in Excel file for further processing. I am not able to figure out how to do that.
I am attaching my segmented image with multiple ROIs.
Thanks in advance. Sunetra Banerjeehttps://kr.mathworks.com/matlabcentral/profile/authors/15448075tag:kr.mathworks.com,2005:Question/8552852021-06-13T17:43:25Z2021-06-15T00:54:49ZI have a time series which my sensors recorded them in this format: 10.02.42.415 instead of this: 10:02:42.415 ! How can I fix my entire array (which is 465637 samples!)??One of my sensors had an error during my data collection apparently and recorded the time series in a wrong format. I need to convert 10.02.42.415 to this: 10:02:42.415 in order to sync this time series with my other sensors. Thank you for your helpKhashayarash Abashttps://kr.mathworks.com/matlabcentral/profile/authors/22827077tag:kr.mathworks.com,2005:Question/8526252021-06-10T06:08:10Z2021-06-15T00:50:45ZModelling Wave Forces on a BuoyHi all,
I'm still very, very new to the Simulink/Simscape side of the MATLAB/Mathworks suite. I have been trying for the last few hours to find a method of converting the heave wave forces on a buoy into a functional method for finding its position at a certain time. Effectively, this involves an external force of oscillating magnitude acting as given by the attached function. Despite my best efforts, however, my system appears to create a constant upwards load (which is greatly overshadowed by the force of gravity. Am I missing something? Please let me know. Ben Haubenhttps://kr.mathworks.com/matlabcentral/profile/authors/17786844tag:kr.mathworks.com,2005:Question/8560352021-06-14T15:35:27Z2021-06-15T00:47:01ZHow to index one array by assigned vector in certain dimensionHi,
I'd like to form a new 2D array by indexing another 3D array, where the indexing is via one assigned vector.
Details like below:
Given arr_i,vec_i, want to find func_index as
arr_o = func_index(arr_i,vec_i);
%%%
arr_i1 = [111,112,113,114; ...
121,122,123,124];
arr_i2 = [211,212,213,214; ...
221,222,223,224];
arr_i3 = [311,312,313,314; ...
321,322,323,324];
arr_i = cat(3,arr_i1,arr_i2,arr_i3);
vec_i = [2,3,1,2];
arr_o = func_index(arr_i,vec_i);
%%%
With above operation, I expect arr_o will be
[211,312,113,214; ...
221,322,123,224];
The in/out relationship of func_index is:
arr_o(1:2,1) = arr_i(1:2,1,2), since vec_i(1) == 2;
arr_o(1:2,2) = arr_i(1:2,2,3), since vec_i(2) == 3;
arr_o(1:2,3) = arr_i(1:2,3,1), since vec_i(3) == 1;
arr_o(1:2,4) = arr_i(1:2,4,2), since vec_i(4) == 2;
Keypoint here is assigned vector actually index 3D array in certain one dimension (in this case is dim_3), and result in new 2D array.
Please propose matrix operation (avoiding loop, since the real array is quite big).
Thanks!!Warren Chuohttps://kr.mathworks.com/matlabcentral/profile/authors/19711099tag:kr.mathworks.com,2005:Question/8563352021-06-15T00:46:22Z2021-06-15T00:46:22ZConnection test problem when I configure IP for Xilinx FPGA ZedBoard and Ubuntu hostDear Sir,
I am working on designing a software-defined radio. The host is installed Ubuntu 18.04 system.The version of Matlab is 2020a. The hardware is ZedBoard which is integrated with FM-COMMS3 (AD9361). After installing the communication toolbox for Xilinx radio platform(Communications Toolbox™ Support Package for Xilinx® Zynq®-Based Radio), I tried to to set up the hardware. It occurs that the interactive UI is only available for Windows.
So I setup the hardware manually according https://www.mathworks.com/help/supportpkg/xilinxzynqbasedradio/ug/manual-host-radio-hardware-setup.html?s_tid=srchtitle.
step 1-5 are successful.
In the step 6, Verify Radio Hardware Setup, after input
testConnection(dev,'192.168.3.1');
I got errors like:
I "confirmed the follwing", but got the same errors.
Cloud any help me, thanks.xioabo lihttps://kr.mathworks.com/matlabcentral/profile/authors/15011999tag:kr.mathworks.com,2005:Question/8541902021-06-11T21:02:06Z2021-06-15T00:36:24ZWhat changes should I make to get binary images correctly in order for BoundingBox to grab the ROI correctly?I am not getting the correct binary images of the attached images in order for the BoundingBox to capture the ROI properly. It happens only for a few images most likely due to the pixel values that are thresholded. What modifications would have to be done in the code to get the correct binary image in order to capture the ROI properly for these images. The original images attached are in RGB color. The corresponding binary image are displayed below.
folder = 'I:\converted images\0.5\0.5 2 mm offset';
baseFileName = '0.5 cmc 2mm off0590.tif';
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~isfile(fullFileName)
% The file doesn't exist -- didn't find it there in that folder.
% Check the entire search path (other folders) for the file by stripping off the folder.
fullFileNameOnSearchPath = baseFileName; % No path this time.
if ~exist(fullFileNameOnSearchPath, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
fullFileName = fullFileNameOnSearchPath;
end
[grayImage,map] = imread(fullFileName);
grayImage = rgb2gray(grayImage);
imshow(grayImage,map)
binaryImage = ~imbinarize(grayImage);
% Erase from line 758 down:
binaryImage(758:end, :) = false;
% Fill holes.
binaryImage = imfill(binaryImage, 'holes');
% Get rid of any msall noise blobs.
binaryImage = bwareafilt(binaryImage, 1); % Take largest blob only.
imshow(binaryImage)
impixelinfo;
props = regionprops(binaryImage, 'BoundingBox');
spreadingWidth = props.BoundingBox(3)
rectangle('Position', props.BoundingBox, 'Edgecolor', 'g', 'LineWidth', 2)
naygarphttps://kr.mathworks.com/matlabcentral/profile/authors/11284588tag:kr.mathworks.com,2005:Question/6335442020-11-02T08:34:48Z2021-06-15T00:28:15ZCorrect image distortion with reference imageHey, how can I correct an image for lense distortion using a reference image and control points and perform a cross correlation between the two images afterwards? I feel like the code that I have used is not the best way to do it...
orthophoto = imread('cropped_image.tif');
figure, imshow(orthophoto)
unregistered = imread('cropped_image2.tif');
figure, imshow(unregistered)
pause
[movingPoints, fixedPoints] = cpselect(unregistered,orthophoto,'Wait',true);
cpselect(unregistered, orthophoto)
mytform = cp2tform(movingPoints, fixedPoints,'projective');
t = fitgeotrans(movingPoints, fixedPoints,'projective');
registered = imtransform(unregistered, mytform);
Rfixed = imref2d(size(orthophoto));
registered = imwarp(unregistered,t,'OutputView',Rfixed);
figure1 = imshow(registered);
saveas(figure1,'undistorted.tif');windmillhttps://kr.mathworks.com/matlabcentral/profile/authors/19830111tag:kr.mathworks.com,2005:Question/8534352021-06-10T22:01:33Z2021-06-15T00:13:19ZReset timer to zero after leaving a state with a transition actionI am working on a Stateflow block.
In it I have a state A. In the block, the state A can transition to B, back to A, from A to C, and then back to A.
During the transition from A to B I want to reset the internal clock to zero since there were some other processes happening before but all the interesting stuff starts when going from A to B. I'm also collecting data with a sensor in real time for the entire simulation, so it would be nice to have a final output like this.
t = [0, 0.01, 0.02, ...
T, 0, 0.01, 0.02, ...
];
F = [f(0), f(0.01), f(0.02), ...
f(T), f(T+0.01), f(t+0.02), f(t+0.03),...
];
I'm trying to illustrate that even though the clock reset at t = T, that F keeps on collecting data for each time step before and after until the simulation is done.
EDIT: I forgot to describe what I've done so far.
So far I have simply grabbed the current simulation time upon entering state A for the first time. If there's no way to "restart the clock" then I was simply going to subtract it from the time. It would give some negative times in my array but it would probably work sufficiently well for my case. But I would prefer to "restart the clock".
Is there an easy way to set the clock back to zero? Any tool has to be compatible with the 2016a version of MatLab/Simulink since that's what we use in the lab.
Thanks.Nathaniel H Wernerhttps://kr.mathworks.com/matlabcentral/profile/authors/9280119tag:kr.mathworks.com,2005:Question/1413812014-07-11T06:25:55Z2021-06-15T00:11:01ZFM Radio (Transmitter + Receiver) in MatlabHello all.
I want to design an FM radio (transmitter + receiver) using Matlab (not Simulink). Is it possible in Matlab? If yes, how? I am using stereo headphones as antenna on my laptop but I don't know how to get the signal from the headphone into Matlab code.
Best regards.Zadranhttps://kr.mathworks.com/matlabcentral/profile/authors/5456452tag:kr.mathworks.com,2005:Question/8562902021-06-14T22:41:59Z2021-06-15T00:09:03ZHow to improve efficiency when checking for unique combinations of table values?Hello, I am trying to check each row in a sheet of data to see if it contains a combination of 2 values. For example, there might be a table like
Fruit | Color | related value
apple | blue | 3
apple | red | 8
banana | blue | 5
banana | yellow | 6
apple | blue | 16
pear | yellow | 7
I want to create a table with the first column as the top row and the second column as the first column, and with the values indicated by a corrdinate pair being the number of times that that particular pair appears.
For example:
apple | banana | pear
blue 2 1 0
red 1 0 1
yellow 0 1 1
I'm currently using code that looks like this
fileContents = zeros(size((colorNames,1),size(fruitNames,1));
for p = 1:size(uniqueFruitNames,1)
for q = 1:size(uniqueColorNames,1)
for k = 1:size(rawData,1)
if ((uniqueFruitNames(p) == rawData(k,1)) && (all((uniqueColorNames(q,:) == rawData(k,2))))
fileContents(q,p) = fileContents(q,p) + 1;
end
end
end
end
My problem is that the table that is referenced by my code contains upwards of 10 thousand values, and I have found that the above code take approximately 15 minutes to complete. The rawData sheet contains around 12 thousand rows and 70 columns. The uniqueFruitNames array is 8 x 1, and the uniqueColorNames array is aproximately 2000 x 1.
What can I do to make this more efficient? Dillon Heidenreichhttps://kr.mathworks.com/matlabcentral/profile/authors/20771458tag:kr.mathworks.com,2005:Question/3558892017-09-09T21:33:38Z2021-06-15T00:01:28ZHow to plot a circle of some radius on a polar plot, when the circle is not centered in the origen?eg. i want a small circle with other point as center of some radius...ON the POLAR plotGabriel Malagon Carvajalhttps://kr.mathworks.com/matlabcentral/profile/authors/4873964tag:kr.mathworks.com,2005:Question/4433562019-02-05T18:14:39Z2021-06-15T00:00:00ZPackage app with multiple GUIsHi have coded an app that employs several UI figures as well as multiple functions, and I would to package it to a mlapp.install file. To do so, I open the starting app in the App Designer, click on "Share", "Matlab App". As the main file I have said app and, as the dependency analysis does not return any files, I include all the other apps and functions on shared resources. However, once I have installed the app and run it, it does not find any of the apps or functions that were included in shared resources.
It has to be a Matlab App, not a standalone program. Thank you.Rafael Félix Sorianohttps://kr.mathworks.com/matlabcentral/profile/authors/14105160tag:kr.mathworks.com,2005:Question/8533452021-06-10T19:53:56Z2021-06-14T23:46:41ZFitting cone/cylinder of known dimensions to 3D surface dataI'm looking to fit a cone/cylinder of known dimensions to 3D surface data.
As a test, I created a cone using the parametric equations and downsample it to get some 3D surface data (see photo).
I need to fit to this data a cone whose dimensions are fixed but its orientation and origin are variable (so total 6 unknowns). These 6 parameters need to be determined (in the least square sense) based on the available data.
What would be the best approach to perform this?
I am using the following but so far have not had good luck with it.
A function that uses fsolve to get the cone surface from an implicit form of the cone equation given the 6 parameters.
lsqcurvefit that calls the above function and compares with the 3D data to optimize the 6 parameters.
Thanks!APhttps://kr.mathworks.com/matlabcentral/profile/authors/16072432tag:kr.mathworks.com,2005:Question/8563052021-06-14T23:06:56Z2021-06-14T23:46:35ZHow can I grab only certain files from a folder?Hello.
I currenlty have a folder labeled "2021-06-14". Inside are .csv files from the entire day in 15 minute increments labeled "Data 2021-06-14 00-00.csv, Data 2021-06-14 00-15.csv, ... , Data 2021-06-14 23-45.csv". My goal is to, programmatically, pull files 1-x and copy them to another folder.
Any ideas?Brian Gregoryhttps://kr.mathworks.com/matlabcentral/profile/authors/10772565