https://it.mathworks.com/matlabcentral/answers/questionsMATLAB Answers — New Questions2019-07-23T04:54:56Ztag:it.mathworks.com,2005:Question/4728472019-07-22T13:59:09Z2019-07-23T04:54:56ZWhy fwrite is ~320x slower in the second interation and onwards when writing interleaved data?I'd like to write a binary file, which should contain four vectors of integers in the same length in an interleaved fashion.
For example, let si,j denote the sample from the i th channel at time step j.
I can prepare a long vector just as above and then pass it to fwrite and that is easier.
But that design is not great, because when individual vectors are really long, and when I have to accomodate a lot of vectors rather than just four, it will enconter a memory issue.
So, a clever way to to this is to write one vector input at a time without keeping all of them in the memory.
The code like below works, but I found that the performace of fwrite is much worse in the second iteration onwards compared to the first iteration.
While t3 in the first loop was less than a second (0.281 sec), t3 took roughly 1 min 30 sec for the second to fourth iterations (~320 times slower). I wonder why this is so slow, and if there is a work around for this.
fid = fopen(newfile,'w');
for i = 1:4
filepath = fullfile(datadir,filenames{i});
data = load_data(filepath); % int16 vector
status = fseek(fid,(i-1)*2,'bof');
if status == -1
error('fseek failed')
end
t1 = datetime;
fwrite(fid, data, 'int16', 2*(n-1));
t2 = datetime;
t3 = duration(t2-t1) % why this is slower in second iteration and onwards?
end
fclose(fid);
t3 = duration
00:00:00.2810
t3 = duration
00:01:37.2600
t3 = duration
00:01:29.9700
t3 = duration
00:01:29.6490
90 (sec) / 0.281 (sec) == ~320 (times)
Kouichihttps://it.mathworks.com/matlabcentral/profile/authors/3431075-kouichitag:it.mathworks.com,2005:Question/4729572019-07-23T04:45:11Z2019-07-23T04:45:11Zhow can i give gate signal to electronic switches based on algorithm?this model is regarding PV array under partial shading.here the main aim is to improve maximum power under partial shading, so I want to give a gate signal to switches in such a way that switches can operate based on which module is undergoes shading. i want a logic how to give gate in simulink..hope it i'll get it soon.
srinivas chappahttps://it.mathworks.com/matlabcentral/profile/authors/9827777-srinivas-chappatag:it.mathworks.com,2005:Question/4729562019-07-23T04:43:54Z2019-07-23T04:43:54ZHow to make Stroboscopic Motion photography with MatlabHi everyone
Here's a challenge.
If I have a video like Ballet ,how to make stroboscopic photography with Matlab.
Finally, get the following pictures.
zb lihttps://it.mathworks.com/matlabcentral/profile/authors/9448621-zb-litag:it.mathworks.com,2005:Question/4728782019-07-22T17:17:54Z2019-07-23T04:31:53ZGet a property from a classHello,
I have a class as per attached file "ktmDbiAccess.m".
I would like the property "fullFileName" is read ony; in my understanding I have to greate a get method to do that but I cannot understand how. I have found this example but it is not clear me yet how I have to modify the class and how should I call the "get" method in the caller script.
May you please provide an example? Or just modify my class.
regards,
Andrea
Andrea Agostinihttps://it.mathworks.com/matlabcentral/profile/authors/14366116-andrea-agostinitag:it.mathworks.com,2005:Question/4716852019-07-15T00:44:57Z2019-07-23T04:31:39ZIs it possible to set an uncertain parameter (ureal) to a fixed value?Hi,
It is the first time that I use the Robust Control Toolbox. I have a MIMO system (uss) which depends on some uncertain parameters (ureal) and I d like to plot its principal gains for some specific values ot these parameters. Do you know how to set the value of the uncertain parameter to a fixed value in the admissible range?
Thanks!Francesco Rosciahttps://it.mathworks.com/matlabcentral/profile/authors/12665426-francesco-rosciatag:it.mathworks.com,2005:Question/4729552019-07-23T04:30:22Z2019-07-23T04:30:22ZCompute complex matrix exponential inside loop?Hey all,
I'm trying to compute a diagonal complex matrix exponential on matlab using expm, but for some reason the outcome doesn't make any sense. For example, in the code bellow, i have compared the values of the 2x2 matrix D( : , : , 400001), which is a complex diagonal matrix, and expm(D( : , : , 400001)) in H1, and somehow MATLAB doesn't compute the result correctly, it just ignores the complex values. Is there a way to build a matrix from D( : , : , 400001) with only computes the complex exponential of the diagonal values, leaving the non-diagonal elements zero for each interaction? Thanks in advance!
%% Quantum Control
format long
clear all
clc
%% Variables
fs=10;
ft = -20000:1/fs:20000; % Time
alpha = 0.001; % Time parameter
beta = 0.001; % Time parameter
ai = 0.2; % Pop |1>
ai2 = 0.8; % Pop |2>
af = 1; % Pop Final |1>
w0 = 0.02; % w0 = (E2 - E1)/h
mi = 6; % Dipole
phii = pi/24; % Relative phase
phif = pi/4; % Relative phase final
E1 = 1; % Energy
E2 = 1.02; % Energy 2
psii=[0.447213595499958;0.886775242389878 + 0.116746175459296i];
psif=[0.827008128150061 + 0.425427380394792i;0.065941133271320 + 0.361554886531758i];
%% Control function
g = 1./(1+exp(-alpha.*ft));
f = ai*(1-g)+af*g;
p = 1./(1+exp(-beta.*ft));
h = phii*(1-p)+phif*p;
%% Electric field
E = alpha.*(af-ai).*exp(alpha.*ft).*sin(w0.*ft+h)./(mi.*(1+exp(alpha.*ft)).*sqrt((1-ai+(1-af).*exp(alpha.*ft)).*(ai+af.*exp(alpha.*ft))))+2.*beta.*(phif-phii).*exp(beta.*ft).*sqrt(f.*(1-f)).*cos(w0.*ft+h)/(mi.*(1-2.*f).*(1+exp(beta.*ft).^2));
%% Time evolution operator
U = zeros(2,2,length(ft)) ;
for i = 1:length(ft)
H0(:,:,i)=[-1i*E1*ft(i)/2 0;0 -1i*E2*ft(i)/2];
H01(:,:,i)=expm(H0(:,:,i));
H(:,:,i)=[0 1i*mi*E(i)*ft(i);1i*mi*E(i)*ft(i) 0];
[V(:,:,i),D(:,:,i)]=eig(H(:,:,i));
H1(:,:,i)=expm(D(:,:,i));
U(:,:,i)=H01(:,:,i)*V(:,:,i)*H1(:,:,i)*inv(V(:,:,i))*H01(:,:,i);
psi(:,i)=U(:,:,i)*psii;
end
%% Endguilherme stahlberghttps://it.mathworks.com/matlabcentral/profile/authors/13599463-guilherme-stahlbergtag:it.mathworks.com,2005:Question/4729542019-07-23T04:29:12Z2019-07-23T04:29:12ZMath channel for roll rate x roll degrees, trying to add bump rubbers...Math channel for roll rate x roll degrees, trying to add bump rubbers... Not really getting far, suggestions?Patrick Bradfordhttps://it.mathworks.com/matlabcentral/profile/authors/4948253-patrick-bradfordtag:it.mathworks.com,2005:Question/4729532019-07-23T04:24:39Z2019-07-23T04:24:39ZHow capture a image from my laptop and how to store their pixels in excell sheet by converting them to gray color How capture a image from my laptop and how to store their pixels in excell sheet by converting them to gray color PRAJWAL GOWDA HMhttps://it.mathworks.com/matlabcentral/profile/authors/15787827-prajwal-gowda-hmtag:it.mathworks.com,2005:Question/4729492019-07-23T03:43:57Z2019-07-23T04:16:44ZHow do I rearrange a matrix in a loopI want to change the order of each element in a matrix.
For example I need to transform matrix A into matrix B using a For loop.
A =
10 5
4 10
2 3
B =
10 5 0 0 0 0
0 0 4 10 0 0
0 0 0 0 2 3
10 0 4 0 2 0
0 5 0 10 0 3
Daniel Aguirrehttps://it.mathworks.com/matlabcentral/profile/authors/11650195-daniel-aguirretag:it.mathworks.com,2005:Question/4727492019-07-22T05:51:47Z2019-07-23T04:10:24ZInterpolating random values to smoothen a curveI need to smoothen curve on this graph and remove the noise in it.I can either use interpolation or curve fitting. I am not able to do it using curve fitting toolbox.How can I do it..??
Abhiraj Guptahttps://it.mathworks.com/matlabcentral/profile/authors/15711694-abhiraj-guptatag:it.mathworks.com,2005:Question/4729502019-07-23T03:55:33Z2019-07-23T04:08:06ZI cant get fprintf to workI just want to display the values. For some reason it wont display some of them and the ones that are displayed are in scientific notation. How can I correct my code so that all values are displayed and how can I make the numbers be in regular notation (Ex: 4.66 instead of 4.660000e+1)
%% Loading the data
clc
load carbig;
%% Exploring two variables
%Miles Per Galon
a= min(MPG);
b= max(MPG);
c= mode(MPG);
d= nanmean(MPG);
fprintf('Minimum MPG is %s, Maximum MPG is %s, Mode MPG is %s and Mean MPG is %s\n',a,b,c,d)
Not_sharpest_tool.mathttps://it.mathworks.com/matlabcentral/profile/authors/12604147-not_sharpest_tool-mattag:it.mathworks.com,2005:Question/4729522019-07-23T04:05:37Z2019-07-23T04:05:37Zhow to share a variable from one method to another method? classdef Sample
properties
a
b
end
methods
function f1 = form1(this)
f1 = 1 ./ this.a; % how to share this variable to other methods (in this example form2)?
end
function f2 = form2(this)
f2 = f1 .^ 2;
end
end
endmadhan ravihttps://it.mathworks.com/matlabcentral/profile/authors/12308260-madhan-ravitag:it.mathworks.com,2005:Question/4729512019-07-23T04:05:15Z2019-07-23T04:05:15ZMeasuring Impedance Simulation Error Need Help!I am trying to measure impedance in the simulations below. It appears that when the source resistance in the simulation changes from the a (0.1 Ohms) version to the b (100 Ohms) version the simulations gives very different plot results. This appears to violate Ohm's law since the source resistance should not be considered when measuring the impedance of the circuit on the right and should give the same overall impedance measured in the plot. Can anyone explain my error and show me a correct simulation measuring the impedance without the source resistance affecting the plot results? Future thanks.Christopher Danielhttps://it.mathworks.com/matlabcentral/profile/authors/9949469-christopher-danieltag:it.mathworks.com,2005:Question/4713872019-07-12T03:33:16Z2019-07-23T04:02:17ZHow to convert raw FLIR thermal images(.jpg) into .txt files?I needed to convert Raw thermal images from FLIR camera which is in .jpg format to be converted to text files, extracting its meta data!Jubin Mathaihttps://it.mathworks.com/matlabcentral/profile/authors/14142284-jubin-mathaitag:it.mathworks.com,2005:Question/4729292019-07-22T23:56:41Z2019-07-23T03:58:13ZWhat is wrong in my ploteh = 8.854e-12;
h = 50e-9;
e0 = (1.465^2)*eh;
e1 = (1.624^2)*eh;
e2 = (1.333^2)*eh;
w1 = 450e-9;
w2 = 750e-9;
for i=1:100
w(i) = w1 + (i-1)/100*(w1-w2);
r01(i) = (sqrt(e0 - e0*0.9806)/e0 - sqrt(e1 - e0*0.9806)/e1)/(sqrt(e0 - e0*0.9806)/e0 + sqrt(e1 - e0*0.9806)/e1);
r12(i) = (sqrt(e1 - e0*0.9806)/e1 - sqrt(e2 - e0*0.9806)/e2)/(sqrt(e1 - e0*0.9806)/e1 + sqrt(e2 - e0*0.9806)/e2);
kz(i) = 2*pi/w(i)*sqrt(e1 - e0*0.9806);
R(i) = (r01(i) + r12(i)*exp(2*1i*kz(i)*h))/(1 + r01(i)*r12(i)*exp(2*1i*kz(i)*h));
end
plot(w,abs(R));Aravind Varmahttps://it.mathworks.com/matlabcentral/profile/authors/10335353-aravind-varmatag:it.mathworks.com,2005:Question/4712672019-07-11T12:24:39Z2019-07-23T03:55:28Zinterpolate curve to some blobhi i have x,y point of curve i want to create some interpolation that will add x,y points . i want that line will pass in the direction of the blob and even in the center of the mass . it should be smooth. here is example figure : the black curve below is given and i want to continue it to the blob above(as the dotted).
dror yeminihttps://it.mathworks.com/matlabcentral/profile/authors/12421789-dror-yeminitag:it.mathworks.com,2005:Question/2595542015-12-09T13:31:12Z2019-07-23T03:54:55ZSpline fitting with repeated X'sso here is my matlab code, and the problem is there is repeated x values and spline fit code doesn't work how can i make it so it only takes the first x and doesn't take the repeated ones? And im not good at matlab so, can you please show how to add the code or add it to the original code.
load Pvst1.txt
load Fvst1.txt
tx = Pvst1(:,1);
tF = Fvst1(:,1);
x = Pvst1(:,2);
F = Fvst1(:,2);
tq=0:0.01:5.81;
Fq = interp1(tF,F,tq,'spline');
xq = interp1(tx,x,tq,'spline');
plot(xq,Fq,'ko');
hold on
xlabel('Position (m)','Fontsize',24)
ylabel('Force (N)','Fontsize',24)
title('Force vs. Position for car, Part A','Fontsize',24)
grid on
hold on
Olca Orakcihttps://it.mathworks.com/matlabcentral/profile/authors/7387729-olca-orakcitag:it.mathworks.com,2005:Question/4727782019-07-22T08:51:56Z2019-07-23T03:54:05ZCreating new matrix from the second column of other matricesHi,
I have 10918 matrices with dimensions of [1000*4].
I want to create a new matrix which its columns are the second column of 10918 matrices which I have.
These 10918 matrices are .plt file and their name are as : PIV_1, PIV_2, PIV_3,....,PIV_10918.
For example:
PIV_1=[x_1,y_1,u_1,v_1]
PIV_2=[x_2,y_2,u_2,v_2]
...
PIV_10918=[x_10918,y_10918,u_10918,v_10918]
new matrix=[y_1,y_2,...,y_10918]
I am sorry if i cant explain well . Thanks in advance for your help.
Shabnam Mhttps://it.mathworks.com/matlabcentral/profile/authors/15842580-shabnam-mtag:it.mathworks.com,2005:Question/1331442014-06-08T08:26:59Z2019-07-23T03:53:39ZHow can I show a video.mp4?Hi,
I don't know how to show a video in mp4 format on matlab. I used video = VideoReader(video.mp4) and then movie(video), but it doesn't work!
Can u help me?
Thanks,
GDGiacomohttps://it.mathworks.com/matlabcentral/profile/authors/5355913-giacomotag:it.mathworks.com,2005:Question/4728972019-07-22T19:30:08Z2019-07-23T03:53:06ZHow can I find RGB values of a matrix of coordinates of an image?Hi,
I'm trying to pull the RGB values from a list of (x,y) coordinates that are centers of circles. My plan was to get the matrix of each component (r, g, and b) this way:
P = imread('image'); ...
x = centers(:, 1);
y = centers(:, 2);
rcenters = P(round(x), round(y), 1);
x is a 668 x 1 matrix, and so is y, so I was hoping rcenters would be 668 x 2, but instead it's 668 x 668, which does not make sense to me. I had to round the x and y coordinates to the nearest integer so that it would have integer indices.
How could I get it to return a 668 x 2 matrix with the R value of the x coordinate in column 1 and the R value of the y coordinate in column 2?
Thanks in advance!Eric Martzhttps://it.mathworks.com/matlabcentral/profile/authors/14676556-eric-martztag:it.mathworks.com,2005:Question/4727322019-07-22T01:59:45Z2019-07-23T03:44:46ZEquation from Curve FittingHi, MATLAB Community! I was able to plot my data using Curve Fitting but I need the equation from the curve. How can I export the equation of the curve generated?Nhoja Marie Chuahttps://it.mathworks.com/matlabcentral/profile/authors/15605892-nhoja-marie-chuatag:it.mathworks.com,2005:Question/4720842019-07-17T05:48:33Z2019-07-23T03:42:25ZHow to parse text data Hi
I have data in the below format. I need the mechanism to parse the data from below format with expected output.
Input data format:
07/16 12:55:22.012 INFO | test_runner_utils:0812| Began logging to /tmp/test_that_results_hatch_deL3lZ
07/16 12:55:27.477 INFO | test_runner_utils:0259| autoserv| Processing control file
Expected Output format:
Define level of message extraction based on the marker sign ==> |
-Step 1: Extract Timestamp in mm/dd HH:MM:sec.millisec <string>|
-Step 2: Extract Timestamp in mm/dd HH:MM:sec.millisec <string>| extract full text in a variable, option to grab variable if associated with value
-Step 3: Extract Timestamp in mm/dd HH:MM:sec.millisec <string>|<string>:%1.3f|
-Step 4: Extract Timestamp in mm/dd HH:MM:sec.millisec <string>|<string>:%1.3f|extract full text in a variable, option to grab variable if associated with value
-Step 5: Extract Timestamp in mm/dd HH:MM:sec.millisec <string>|<string>:%1.3f|<string>|
-Step 6: Extract Timestamp in mm/dd HH:MM:sec.millisec <string>|<string>:%1.3f|<string>|extract full text in a variable, option to grab variable if associated with value
Input data format:
07/16 12:55:27.620 DEBUG| utils:0287| [stdout] CHROMEOS_RELEASE_BOARD=hatch
07/16 13:28:58.330 INFO | mode_switcher:0673| -[FAFT]-[ start wait_for_client ]---
Expected Output format:
-Step 1: Extract Timestamp in mm/dd HH:MM:sec.millisec <string>|<string>:%1.3f|<[string]>
-Step 2: Extract Timestamp in mm/dd HH:MM:sec.millisec <string>|<string>:%1.3f|<[string]> extract full text in a variable, option to grab variable if associated with value
-Step 3: Extract Timestamp in mm/dd HH:MM:sec.millisec <string>|<string>:%1.3f|<[string]>
-Step 4: Extract Timestamp in mm/dd HH:MM:sec.millisec <string>|<string>:%1.3f|<[string]> [string] extract full text in a variable, option to grab variable if associated with value
Input data format:
2019-07-16 12:55:30 > string
2019-07-16 12:55:30 powerbtn: released
Expected Output format:
Note the marker >
-Step 1: Extract Timestamp in YYYY:MM:DD HH:mm:sec > < string>
-Step 2: Extract Timestamp in YYYY:MM:DD HH:mm:sec < full string>
Input data format
2019-07-16 12:55:31 > [12074.734997 HC 0x121 err 1]
Expected Output format
-Step 1: Extract Timestamp in YYYY:MM:DD HH:mm:sec > [< %1.3f string extract full text in a variable, option to grab variable if associated with value>]
Thanks a lotsriram shastryhttps://it.mathworks.com/matlabcentral/profile/authors/7949204-sriram-shastrytag:it.mathworks.com,2005:Question/4729482019-07-23T03:41:02Z2019-07-23T03:41:02ZImage acquisition and storageHow to capture an image from webcam, convert the image to matrix form and store the matrix in an excel sheet?Shreya Shettyhttps://it.mathworks.com/matlabcentral/profile/authors/12425246-shreya-shettytag:it.mathworks.com,2005:Question/4729472019-07-23T03:39:47Z2019-07-23T03:39:47ZHow to store the matrix of an image in an excel sheet?Image is present in a folder. I want to store is matrix in an excel sheet. How to proceed?Shreya Shettyhttps://it.mathworks.com/matlabcentral/profile/authors/12425246-shreya-shettytag:it.mathworks.com,2005:Question/4727462019-07-22T05:42:51Z2019-07-23T03:38:11Zcreating an image databasei want to create a database of images present in a folder by converting it to binary format.
can u pls share the procedure or the source code.
thank you
Shreya Shettyhttps://it.mathworks.com/matlabcentral/profile/authors/12425246-shreya-shettytag:it.mathworks.com,2005:Question/4729462019-07-23T03:35:38Z2019-07-23T03:35:38ZUndefined function or variable.
clear; clc;
m_proj('Miller','lat',[0 14],'lon',[95 126]);
% Generate a smaller coastline for faster plot
m_gshhs_f('save','RTKNET');
dir = 'C:\Users\ACER\Documents\1-DOKUMEN\5-DOKUMEN MAT NIZAM\PSM\all\5-RESEARCH INFORMATION\RADS\m_map';
file = 'Wave_climatology(SW).asc';
%out = 'M2_aaaa.xlsx';
name = 'Significant Wave Height Climatology over Malaysian Seas during Southwest Monsoon from 1993 to 2016 (May-August) ';
cd(dir)
Data = textread(file);
lat = Data(:,1);
lon = Data(:,2);
geoid = Data(:,3); % unit 3 (m) 5 (cm)
% Specifying map projection
figure;
m_proj('Miller','lat',[0 14],'lon',[95 126]);
% Contour & colour settings
dx =95:0.25:126; % set the min,max latitude and interval
dy = 0:0.25:14+1; % set the min,max longitude and interval
[Xi,Yi] = meshgrid(dx,dy);
[Zi] = surfergriddata(lon,lat,geoid,Xi,Yi);
% datata = [Zi];
% xlswrite(out, datata);
% %xlswrite(latname, Yi);
% %xlswrite(longname, Xi);
m_pcolor(Xi,Yi,Zi)
shading interp;
colormap jet;
% Coastline & grid
m_gshhs_f('patch',[1 1 1]);
m_gshhs_f('color','k');
m_usercoast('RTKNET','color','k');
m_grid('linestyle','none','box','fancy','tickdir','in');
% Labels & colorbar
title(name,'FontWeight','bold','FontSize',12);
xlabel('Longitude','FontWeight','bold','FontSize',12);
ylabel('Latitude','FontWeight','bold','FontSize',12);
%[X,Y]=m_xy2ll(lon,lat);
%m_line(lon,lat,'linewi',4,'color','r');
%m_line(amp1,lon1,'linewi',4,'color','b');
% caxis([28.28,30.97])
%cb = colorbar('h');
%set(get(cb,'xlabel'),'String','Amplitude (m)','FontWeight','bold');
set(get(colorbar,'ylabel'),'String','Significant Wave Height (m)','FontWeight','bold')
Error:
Undefined function or variable 'Zi'.
Error in mapping1 (line 46)
[Zi] = surfergriddata(lon,lat,geoid,Xi,Yi);Mat Nizam Utihttps://it.mathworks.com/matlabcentral/profile/authors/13745921-mat-nizam-utitag:it.mathworks.com,2005:Question/4729392019-07-23T02:39:05Z2019-07-23T03:32:05ZUnable to acquire image with connected teledyne dalsa cameraGreetings,
So I am currently working on a project where I have to acquire a significant number of images through a teledyne dalsa x-ray detector. So the dectector(camera) connected to my computer under the gigecam pretense; however, when I try to acquire image(snapshot command) it returns the message
"Time out occurred while trying to get a frame from the camera."
furthermore, I just learned that teledyne dalsa has a separate support package than the standard gigecam, so could it be that I am not connecting using the right connector?Ou Lihttps://it.mathworks.com/matlabcentral/profile/authors/7895554-ou-litag:it.mathworks.com,2005:Question/4729452019-07-23T03:26:52Z2019-07-23T03:26:52ZFITCKNN with large data sets?Hello, I have some dataset with size of 39366*9 table which I need to apply KNN regression.
My problem arises when I use all the data set the MATLAB gives me an error message:
Error using bsxfun
Requested 900000000x1 (6.7GB) array exceeds
maximum array size preference. Creation of arrays
greater than this limit may take a long time and
cause MATLAB to become unresponsive. See array
size limit or preference panel for more
information.
Error in comparison2 (line 81)
S1 =
fitcknn(array2table(X_norm),y,'NumNeighbors',K3,'Standardize',1
I have searched this errror and found some solution suggesting using tall arays
when I tried it this error appears
Error using fitcknn (line 247)
FITCKNN does not support tall arrays.
My question is, is it possible to use fitcknn with all of this data or should I try something else? if possible how can I do that?omar khaterhttps://it.mathworks.com/matlabcentral/profile/authors/8700367-omar-khatertag:it.mathworks.com,2005:Question/4729442019-07-23T03:23:47Z2019-07-23T03:23:47ZHow do I separate the white pixel data from binary image?Basically, I applied thresholding using Otsu's method and it gave me the below image.
I want to separate the white pixel data from this binary image and convert it back to the rgb image for further use.
How do I separate the white pixels?
Ritwik Dharhttps://it.mathworks.com/matlabcentral/profile/authors/12318539-ritwik-dhartag:it.mathworks.com,2005:Question/4729402019-07-23T02:43:47Z2019-07-23T03:07:12ZEvaluating a function f(x,y) for any two user-defined valuesWriting a MATLAB program to evaluate a function f(x,y) for any two user-defined values x and yIbrahim Opeyemihttps://it.mathworks.com/matlabcentral/profile/authors/15810429-ibrahim-opeyemitag:it.mathworks.com,2005:Question/4729422019-07-23T03:04:54Z2019-07-23T03:04:54ZFlat field before/after RGB2gray? Noise Reduction. Which is bettter?I desire to remove the noise present in my image.
My original image is RGB image and the image processing for my project is done on grayscale image.
I found the either of following ways give different result.
RGB -> imflatfield (image, 20) -> RGB2gray.
RGB -> RGB2Gray() -> imflatfield(grayImage, 20)
What is the best method to remove the noise. Rajesh Konthamhttps://it.mathworks.com/matlabcentral/profile/authors/14237165-rajesh-konthamtag:it.mathworks.com,2005:Question/4720832019-07-17T05:47:44Z2019-07-23T03:02:56ZHow to change model parameter value in exported simbiology model?I need to change the model parameter value in exported simbiology model. How can do it in command mode?Rajeev Kumarhttps://it.mathworks.com/matlabcentral/profile/authors/8296466-rajeev-kumartag:it.mathworks.com,2005:Question/4728292019-07-22T12:06:38Z2019-07-23T02:57:18ZWhy are condition2 condition3 and condition4 not logical?a=0.336;
Ta=9.476;
Te=1.208;
Tw=1.498;
eqh=[0.661;0.619;0.568];
ex=[-1.24;-1.346;-1.441];
en=-ex;
ey=[0.376;0.705;0.968];
eqx=[-0.309;-0.357;-0.392];
eh=[1.594;1.583;1.545];
eyqh=[0.642;0.78;0.897];
a0=a*Ta*Te^2;
r = -100:1:100;
[bt,Td]=meshgrid(r);
i=1;
figure('Name','Stable');
Kp=1./bt;
exqh(i)=en(i).*eqh(i)+eqx(i).*eh(i);
Ki=1./(bt.*Td);
a1=Ta.*Tw.*eqh(i)+a.*Te^2.*en(i)+a.*Te^2.*ey(i).*Kp;
a2=a.*Te^2.*Ki*ey(i)+Ta+Tw.*exqh(i)-eyqh(i).*Kp.*Tw;
a3=en(i)+ey(i).*Kp-eyqh(i).*Ki.*Tw;
a4=ey(i).*Ki;
condition1 =a1>0; output = ones(length(r));condition2=zeros(size(condition1));condition3=zeros(size(condition1));condition4=zeros(size(condition1));
for j=1:numel(a1)
condition2(j)=det([a1(j) a0;a3(j) a2(j)])>0;
condition3(j) =det([a1(j) a0 0;a3(j) a2(j) a1(j);0 a4(j) a3(j)])>0;
condition4(j)=det([a1(j) a0 0 0;a3(j) a2(j) a1(j) a0;0 a4(j) a3(j) a2(j);0 0 0 a4(j)])>0;
end
output(~(condition1 & condition2 & condition3 & condition4)) = 0;
imshow(output, 'xdata', r, 'ydata', r);
axis on;
Why are condition2 condition3 and condition4 not logical?zhenyu zenghttps://it.mathworks.com/matlabcentral/profile/authors/14061743-zhenyu-zengtag:it.mathworks.com,2005:Question/4729412019-07-23T02:54:35Z2019-07-23T02:54:35ZOnline parameter optimization using genetic algorithm - Experimental setupI'm currently working on a project that intents to reduce the amplitude of vibration on a cylinder caused by transverse water flow ( VIV phenomen).
The actuator is basically composed by 4 dc motors around the main cylinder that produces a disturb on the flow and, over specific range of rotation, can reduce the response amplitude of the main cylinder.
The idea is to use a MOEA ( Multi Objective Evolutionary Algorithm) to find optimal rotation of each cylinder that reduce the vibration while optmize power consumption.
My simulink model to manual run DC motor is already woking properly, runing on external mode, using a S-Function to control the motors conected to a Arduino boad.
Unfortunatelly, when I try to test a simple optimization, it fails. As I don't have experimental setup built yet, tested a simple objective function optimization while running he DC motor on external mode. A known simple cost function (y= x^2 -6x) to have the value 'x' minimized between lower and upper boundary [0 ; 6] should be found as "x = 3, y -9" after some iterations ( using fminsearch", "ga"or any other optimization tool). The idea is to use each iteration value to run DC motor at a specific rotation, add a delay for a few seconds, and release to run next iteraton until optimization converge. I tried simulate a simple using simulink tool "Analysis - Parameter Optimization" (1) or by code usinga wrapper function using "coder-extrinsic" comand (2). Important to remember that this is easily achieved on simulnk "normal mode", the problem is when I run on "external mode".
Below ate the errors found:
(1) Changing property 'ReturnWorkspaceOutputsName' is not allowed
(2)The function 'fmincon' is not supported for standalone code generation. See the documentation for coder.extrinsic to learn how you can use this function in simulation.
So, basically my question is: How can I run parameter optimization over online experimental data, simulink external mode, where the cost function is unknown ( I only have the response value measured) and the parameters tested at each step are used to generate next response.
Paulo Naveshttps://it.mathworks.com/matlabcentral/profile/authors/15457103-paulo-navestag:it.mathworks.com,2005:Question/4727642019-07-22T07:33:25Z2019-07-23T02:50:45ZHow to use counter for transmitted can message ?Hello ;
I would like to transmit message and calculate checksum via counter ( which is count data 0 to 16) . I arrange CRC-8 and import dbc file from specified database. and I couldnt understand that how to calculate checksum via in this way before transmitting, we will increase 1 and put it in the corresponding byte.
I've attached my script below, if you can help me asap I will be glad.
%% Clear
Clc
Clear
%% Counter
%% Transmit Message
currentFolder = pwd;
txCh = canChannel('PEAK-System','PCAN_USBBUS1')
db = canDatabase(['pwd\ESC_2.dbc']);
txCh.Database = db;
msg = canMessage(db, 'ESC_2');
transmitPeriodic(txCh, ESC_2, 'On', 0.100);
start(txCh);
%% Generate CRC Polynom
gen = crc.generator('Polynomial', '0x1D', 'InitialState', '0xFF', 'ReflectInput', false, 'FinalXOR', '0xFF')
%% Detect the conditions
det = crc.detector('Polynomial', '0x1D', 'InitialState', '0xFF', 'ReflectInput', false, 'FinalXOR', '0xFF')
%% Create Message and Encode iit
msg = canMessage(db, 'ESC_2');
encoded = generate(gen, msg)
%% Introduce an error and detect the error
encoded(1) = ~encoded(1); % Introduce an error
[outdata error] = detect(det, encoded) % Detect the error
noErrors = isequal(msg, 'outdata') % Should be 0
error % Should be 1
pinar adsizhttps://it.mathworks.com/matlabcentral/profile/authors/15787357-pinar-adsiztag:it.mathworks.com,2005:Question/4503562019-03-16T01:26:07Z2019-07-23T02:45:06ZHow can blur an imageWrite a function called blur that blurs the input image. The function is to be called like this:
output = blur(img,w);
where img, the input image is a two-dimensional matrix of grayscale pixel values between 0 and 255. Blurring is to be carried out by averaging the pixel values in the vicinity of every pixel. Specifically, the output pixel value is the mean of the pixels in a square submatrix of size 2w+1 where the given pixel sits in the center. For example, if w is 1, then we use a 3x3 matrix, that is, we average all the neighboring pixels of the given pixel and itself. Only use valid pixels when portions of the blurring matrix fall outside the image. For example, the blurred value corresponding to w = 1 at index (1,1) would be the mean of of elements (1,1), (1, 2), (2,1) and (2, 2). Both input img and output output are of type uint8.
You can download the test image here to use in MATLAB.Jorge Ortizhttps://it.mathworks.com/matlabcentral/profile/authors/7989278-jorge-ortiztag:it.mathworks.com,2005:Question/796072013-06-19T19:34:59Z2019-07-23T02:42:55ZAny way to free hand crop an image?Is there any way to free hand crop on an image? I have an organic shape I want to quickly crop not using the rectangular box that matlab has for cropping. Any way to go about this?Siddharthhttps://it.mathworks.com/matlabcentral/profile/authors/3514023-siddharthtag:it.mathworks.com,2005:Question/4721242019-07-17T10:16:06Z2019-07-23T02:41:44ZHow can I customly fix the Data cursor location in the Matlab plot?I have a plot (attached). In this plot I need to add two data cursors. In one of the data cursor, I need to fix the X value to be 0 and in the other i need to fix the y value to 0. How can I adjust the data cursor points to do so? currently in the first data tip, the Y value is -49.51 and in the other data tip the x value is 0.485. I need to make it in such a way as to keep Y value 0 in first and X value 0 in second. By doing this I will get the corresponding X value from 1st and corresponding Y value from 2ndJaikrishnan Mahalekshmi Sahasranamamhttps://it.mathworks.com/matlabcentral/profile/authors/10119863-jaikrishnan-mahalekshmi-sahasranamamtag:it.mathworks.com,2005:Question/4729322019-07-23T00:51:00Z2019-07-23T02:30:12ZSample rate for interpreted functionI am trying to get a continuous sample rate running using an inperpreted function. However, the interpreted function block doesn't have sample rate input. All the documentation I have read says to double click on the block and set the sample rate. Unfortunatly there is no input block for sample rate in the window. How do I do this?Andrew Crucehttps://it.mathworks.com/matlabcentral/profile/authors/8415492-andrew-crucetag:it.mathworks.com,2005:Question/3725442017-12-12T12:03:42Z2019-07-23T02:23:57ZStacked multi-cuboid geometries with PDE Toolbox for thermal analysis With the PDE Toolbox, I know that I can use the multicuboid function to create a stack of cuboids for thermal analysis, each with their own thermal characteristics. However, it appears that each of the resulting cuboids must have the same width and height as all other cuboids in the stack. To more accurately represent a power semiconductor that I am analyzing, each cuboid would ideally have a different size (thickness, width, and depth). Is it possible to create such a geometry?David Naviauxhttps://it.mathworks.com/matlabcentral/profile/authors/11654400-david-naviauxtag:it.mathworks.com,2005:Question/4729382019-07-23T02:08:15Z2019-07-23T02:08:15Zturn Matlab code involving PDE toolkit into Simscape componentGood morning,
I have a code that depicts the behavior of an SMA material (including thermal and mechanical models, both developed with the PDE toolkit).
Now, since the PDE toolkit has some limitations in terms of 3d geometry when it comes to heat conduction between specifically-shaped solids, I was wondering if I could turn my code into a custom component in Simscape, even though it involves the PDE toolkit...
Is it possible? Any suggestion on how to integrate the code?
Thank you very much,
Giulia Giulia Ulpianihttps://it.mathworks.com/matlabcentral/profile/authors/15681375-giulia-ulpianitag:it.mathworks.com,2005:Question/4726812019-07-21T13:34:41Z2019-07-23T02:07:59ZIf Statement Using Text in a TableWhat commands can I use in the following if statement to specify blank element overwrite?
% Run throught the table of 10 rows
for i = 1:10
% The word "REMOVE" has been used in a previous condition subroutine to specify the row removal in this if statment
if strcmp("REMOVE",table1(i,1)) == 1
% Emptys rows
table1(i,:) = []
else
end
end
The subroutine is executed and the table rows are not being emptied when trueJustinhttps://it.mathworks.com/matlabcentral/profile/authors/2991461-justintag:it.mathworks.com,2005:Question/4729362019-07-23T02:00:34Z2019-07-23T02:00:34ZHow can I classify the tracked position of a blob in a sequence of logical images using MATLAB "Classification Learner"?Hi everyone!
I have simplified my question down to basicly having a sequence of logical images with a blob in them (varying in size and position).
How can I train the classifier to label each blob position? e.g. "TOP', "MIDDLE", "BOTTOM" labels assigend to the blob according to its position within the field of view.
Cheers!kamyar kianoushhttps://it.mathworks.com/matlabcentral/profile/authors/10642796-kamyar-kianoushtag:it.mathworks.com,2005:Question/267882012-01-23T00:44:05Z2019-07-23T01:56:15ZTroubles with saving a modified pathI am using R2011a. I am trying to copy my collection of scripts from an older XP computer to a new Windows7 computer. I have tried a couple of things but most recently I have been copying my scripts to a SanDisk, moving the SanDisk to the Windows 7 computer and copying the scripts into the Windows 7 computer. Then I fire up Matlab and under Set Path I add the folder and sub folders. I can run scripts OK but when I want to save the path I get the following:
"Matlab can not save changes to the path"
"The path file, pathdef.m, might be read only or might be in a folder for which you do not have write access."
The message goes on but in essence I can not save the path for some reason.
Can you point out what I am doing incorrectly?
Thanks.David Koenighttps://it.mathworks.com/matlabcentral/profile/authors/1322461-david-koenigtag:it.mathworks.com,2005:Question/4718962019-07-16T09:09:22Z2019-07-23T01:42:04ZMATLAB start problem.Hello,
I have MATLAB R2019a and every time i open it, it becomes froozen for few minutes and then works.
I receive this attached message after 5 minutes of starting.
Khaled Ibrahimhttps://it.mathworks.com/matlabcentral/profile/authors/14356963-khaled-ibrahimtag:it.mathworks.com,2005:Question/3781892018-01-21T11:05:42Z2019-07-23T01:42:00ZEigen value eigen vectors in matlabI want to solve this question.I'm going to atteched my code but I don't know this code is true.
if true
clc;
clear all;
A=[4 -5;-2 1];
Eig=eig(A)
F=poly(A)
[V,D]=eig(A)
V1=V(:,1)
V11=V1/V(1,1)
endAykut Albayrakhttps://it.mathworks.com/matlabcentral/profile/authors/11315582-aykut-albayraktag:it.mathworks.com,2005:Question/4729172019-07-22T21:53:29Z2019-07-23T01:41:03ZI cannot pass one of the final MATLAB problems on the coursera MATLAB course. What is wrong with my code? Why won't it work for the 'Image Blur' assignment?1st my function
then the code to call it.
what is wrong?
function output=blur(img,w)
img=double(img);
d=w*2+1
s=size(img)
output=[]
for r=1:d:s(1)
row=[];
for c=1:d:s(2)
if r+w<=s(1) && c+w<=s(2) && r-w>=1 && c-w>=1
tot=sum(sum(img((r-w):(r+w),(c-w):(c+w))));
val=tot/(d*d);
nxt=ones(d,d);
nxt(1:end,1:end)=val;
row=[row nxt];
elseif c+w<=s(2) && r-w>=1 && c-w>=1
tot=sum(sum(img((r-w):end,(c-w):(c+w))));
val=tot/(d*(s(1)-r+w));
nxt=ones((s(1)-r+w),d);
nxt(1:end,1:end)=val;
row=[row nxt];
elseif r+w<=s(1) && r-w>=1 && c-w>=1
tot=sum(sum(img((r-w):(r+w),(c-w):end)));
val=tot/(d*(s(2)-c+w));
nxt=ones(d,(s(2)-c+w));
nxt(1:end,1:end)=val;
row=[row nxt];
elseif r+w<=s(1) && c+w<=s(2) && r-w>=1
tot=sum(sum(img((r-w):(r+w),1:(c+w))));
val=tot/(d*(c+w));
nxt=ones(d,(c+w));
nxt(1:end,1:end)=val;
row=[row nxt];
elseif r+w<=s(1) && c+w<=s(2) && c-w>=1
tot=sum(sum(img(1:(r+w),(c-w):(c+w))));
val=tot/(d*(r+w));
nxt=ones((r+w),d);
nxt(1:end,1:end)=val;
row=[row nxt];
elseif r+w<=s(1) && c+w<=s(2)
tot=sum(sum(img(1:(r+w),1:(c+w))));
val=tot/((r+w)*(c+w));
nxt=ones((c+w),(r+w));
nxt(1:end,1:end)=val;
row=[row nxt];
elseif r-w>=1 && c-w>=1
tot=sum(sum(img((r-w):end,(c-w):end)));
val=tot/((s(1)-r+w)*(s(2)-c+w));
nxt=ones((s(1)-r+w),(s(2)-c+w));
nxt(1:end,1:end)=val;
row=[row nxt];
elseif r+w<=s(1) && c-w>=1
tot=sum(sum(img(1:(r+w),(c-w):end)));
val=tot/((r+w)*(s(2)-c+w));
nxt=ones((r+w),(s(2)-c+w));
nxt(1:end,1:end)=val;
row=[row nxt];
elseif c+w<=s(2) && r-w>=1
tot=sum(sum(img((r-w):end,1:(c+w))));
val=tot/((s(1)-r+w)*(c+w));
nxt=ones((s(1)-r+w),(c+w));
nxt(1:end,1:end)=val;
row=[row nxt];
end
end
output=[output;row];
end
row=[]
s2=size(output)
if s2(1)<s(1)
for c=1:d:s(2)
if c+w<=s(2) && c-w>=1
tot=sum(sum(img((s2(1)+1):s(1),(c-w):(c+w))));
val=tot/((s(1)-s2(1))*d);
nxt=ones((s(1)-s2(1)),d);
nxt(1:end,1:end)=val;
row=[row nxt];
elseif c+w<=s(2)
tot=sum(sum(img((s2(1)+1):s(1),1:(c+w))));
val=tot/((s(1)-s2(1))*(c+w));
nxt=ones((s(1)-s2(1)),(c+w));
nxt(1:end,1:end)=val;
row=[row nxt];
elseif c-w>=1
tot=sum(sum(img((s2(1)+1):s(1),(c-w):end)));
val=tot/((s(1)-s2(1))*(s2(2)-c+w));
nxt=ones((s(1)-s2(1)),(s2(2)-c+w));
nxt(1:end,1:end)=val;
row=[row nxt];
end
end
output=[output;row];
end
row=[]
col=[]
s3=size(output)
if s3(2)<s(2)
for r=1:d:s(1)
if r+w<=s(1) && r-w>=1
tot=sum(sum(img((r-w):(r+w),(s3(2)+1):s(2))));
val=tot/(d*(s(2)-s3(2)));
nxt=ones(d,(s(2)-s3(2)));
nxt(1:end,1:end)=val;
col=[col;nxt];
elseif r+w<=s(1)
tot=sum(sum(img(1:(r+w),(s3(2)+1):s(2))));
val=tot/((r+w)*(s(2)-s3(2)));
nxt=ones((r+w),(s(2)-s3(2)));
nxt(1:end,1:end)=val;
col=[col;nxt];
elseif r-w>=1
tot=sum(sum(img((r-w):(r+w),(s3(2)+1):s(2))));
val=tot/((s3(1)-r+w)*(s(2)-s3(2)));
nxt=ones((s3(1)-r+w),(s(2)-s3(2)));
nxt(1:end,1:end)=val;
col=[col;nxt];
end
end
s4=size(col)
if s4(1)<s3(1) || s4(1)<s(1)
tot=sum(sum(img((s2(1)+1):s(1),(s3(2)+1):s(2))));
val=tot/((s(1)-s2(1))*(s(2)-s3(2)));
nxt=ones((s(1)-s2(1)),(s(2)-s3(2)));
nxt(1:end,1:end)=val;
col=[col;nxt];
end
output=[output col];
end
output=uint8(output);
img = imread('vandy.png');
output = blur(img,1);
imshow(output);
Brandon McLaughlinhttps://it.mathworks.com/matlabcentral/profile/authors/15713755-brandon-mclaughlintag:it.mathworks.com,2005:Question/4729332019-07-23T00:54:22Z2019-07-23T01:29:24ZReshape: Math lesson helpCan someone help me with a mathmatics problem?
I have a 5x50 matrix? similar to that of a 5x5x10, but instead of columns the matrix has been organized horizontally.
x1 x1 x1 x1 x1 x2 x2 x2 x2 x2... x5 x5 x5 x5 x5
x1 x1 x1 x1 x1 x2 x2 x2 x2 x2... x5 x5 x5 x5 x5
x1 x1 x1 x1 x1 x2 x2 x2 x2 x2... x5 x5 x5 x5 x5
x1 x1 x1 x1 x1 x2 x2 x2 x2 x2... x5 x5 x5 x5 x5
x1 x1 x1 x1 x1 x2 x2 x2 x2 x2... x5 x5 x5 x5 x5
I would like an algorithm lesson on how to reshape the matrix such that,
x1 x2 x3 x4 x5
x1 x2 x3 x4 x5
. . . . .
. . . . .
. . . . .
x1 x2 x3 x4 x5
Each variable represnts a value that is close but not exactly the same. ie: x1 = 1.1, 1.2, 1.0, 1.1...
and x2 is
2.1, 2.2, 2.1, 2.3....
and so on
The purpose is for data analysis.
This is my partial answer:
%if B is equal to the matrix described above:
B = reshape(B,25,5,2)
Partial because I don't want to store the matrix as two seperate sections but as a complete column such that the matrix is a 50x5.
Can someone explain to me how this math works if I am correct? Also if anybody has a faster/better method that would be awsome.Calvin Changhttps://it.mathworks.com/matlabcentral/profile/authors/11671813-calvin-changtag:it.mathworks.com,2005:Question/4725842019-07-19T22:21:00Z2019-07-23T01:29:03ZHow to put a struct files into a new folderHi guys,
After i use the following code to find files i want, how to put those files into the new folder? Thank you.
This code will give me the info of files in a struct such as name, path, size etc.
files = dir('D:\Data\**\*.mat')Cocohttps://it.mathworks.com/matlabcentral/profile/authors/14458085-cocotag:it.mathworks.com,2005:Question/4726572019-07-21T05:42:04Z2019-07-23T01:27:46ZInsert solar symbol on plot axisHello everyone, how can i insert the solar symbol on my plot axis .tried the following and it doesnt work solar = char(9737) ylabel( ['10^{-6} M_',solar, 'Year^{-1}'], 'FontSize',14,'FontWeight','bold'):it gives “?”instead of solar symbol.helpcharles aouadhttps://it.mathworks.com/matlabcentral/profile/authors/12136039-charles-aouad