https://fr.mathworks.com/matlabcentral/answers/questionsMATLAB Answers — New Questions2021-03-08T10:03:55Ztag:fr.mathworks.com,2005:Question/7660262021-03-08T10:03:55Z2021-03-08T10:03:55ZHow to efficiently compute normal to a surface given surface pointsHi everyone,
I am struggling to understand how to compute normal to a surface on ML.
I have a very simple geometry made by a cone divided both in height and along the circumference, and what I would like as outputs for every area in which the cone is divided are:
The centroid of every single area;
The normal to the area centered on the centroid.
The output I would like is formed by a matrix for the centroids and a matrix for the normals in which each row is formed by a triplet X, Y, Z of the coordinates and values of the centroids and normals respectively.
I attach part of the code for generating a simple cone.
n = 36; % Number of divisions along the circumference
hi = 1; % Number of divisions along the height of the cone (needed for another part of the code)
H = 5; % Height of the cone
r = zeros (1,H/hi);
R = 3; % Base radius
for i = 1:H/hi
r(i) = (1-i*hi/H)*R;
end
[x,y,z] = cylinder(r,n);
z = z*H;alegio20https://fr.mathworks.com/matlabcentral/profile/authors/16823126tag:fr.mathworks.com,2005:Question/7656312021-03-07T21:17:51Z2021-03-08T10:02:34Zvalue must be a double scalerso I am trying to make a cubic equation calculater in matlab but i keep getting the error :
Error using matlab.ui.control.internal.model.AbstractNumericComponent/set.Value (line 111)
'Value' must be a double scalar.
I am really not sure what it means but here is the code:
vala = app.a.Value;
valb = app.b.Value;
valc = app.c.Value;
vald = app.d.Value;
zz1 =(-valb/3*vala)-(1/3*vala)*(0.5*(2*valb^3-9*vala*valb*valc+27*vala^2*vald+sqrt(2*valb^3-9*vala*valb*valc+27*vala^2*vald)^2-(4*valb^2-3*vala*valc)^3)^0.5)^1/3-(1/3*vala)*(0.5*(2*valb^3-9*vala*valb*valc+27*vala^2*vald-sqrt(2*valb^3-9*vala*valb*valc-27*vala^2*vald)^2-(4*valb^2-3*vala*valc)^3)^0.5)^1/3;
zz2 =(-valb/3*vala)+(1+1i*sqrt(3)/6*vala*(0.5*(2*valb^3-9*vala*valb*valc+27*vala^2*vald+sqrt(2*valb^3-9*vala*valb*valc+27*vala^2*vald)^2-(4*valb^2-3*vala*valc)^3)^0.5)^1/3)+(1-1i*sqrt(3)/6*vala)*(0.5*(2*valb^3-9*vala*valb*valc+27*vala^2*vald-sqrt(2*valb^3-9*vala*valb*valc+27*vala^2*vald)^2-(4*valb^2-3*vala*valc)^3)^0.5)^1/3;
zz3 =(-valb/3*vala)+(1-1i*sqrt(3)/6*vala*(0.5*(2*valb^3-9*vala*valb*valc+27*vala^2*vald+sqrt(2*valb^3-9*vala*valb*valc+27*vala^2*vald)^2-(4*valb^2-3*vala*valc)^3)^0.5)^1/3)+(1+1i*sqrt(3)/6*vala)*(0.5*(2*valb^3-9*vala*valb*valc+27*vala^2*vald-sqrt(2*valb^3-9*vala*valb*valc+27*vala^2*vald)^2-(4*valb^2-3*vala*valc)^3)^0.5)^1/3;
app.x1.Value =zz1;
app.x2.Value =zz2;
app.x3.Value =zz3;
p.s if you know any simpler ways that would be big helpMohamed Rashedhttps://fr.mathworks.com/matlabcentral/profile/authors/20064137tag:fr.mathworks.com,2005:Question/7660212021-03-08T10:01:36Z2021-03-08T10:01:36ZODE - Save variables for every time stepHello Guys,
I am stuck with saving time dependent variables inside a model function ... I was browing some already answered questions but none seems to help.
I have the following:
[t, f_val] = ode15s(@model,tspan,yeq);
That yields my f_val as a function of time.
But inside my model function I have also yy variable (time dependent) I would like to trace
function [f, yy] = model(t,yeq)
f= ... %some expression
yy= ... %some expression
How can I extract yy as a function of time?
Cordially skohttps://fr.mathworks.com/matlabcentral/profile/authors/12262922tag:fr.mathworks.com,2005:Question/7633212021-03-04T21:37:06Z2021-03-08T09:59:29ZHow do I convert the vector to matrix 16 * 16 Can anyone help me
In this function i have vector , i want convert the vector to matrix 16 * 16
function inv_s_box = s_box_inversion (s_box)
for i = 1 : 256
inv_s_box(s_box(i) + 1) = i ;%- 1;
endsarahhttps://fr.mathworks.com/matlabcentral/profile/authors/20316273tag:fr.mathworks.com,2005:Question/7637262021-03-05T09:47:04Z2021-03-08T09:59:10ZSelecting Specific Tab in spreadsheetHi (I am fairly new to MATLAB so apologies for any ignorance in the below):
I am trying to import a datasheet with multiple tabs which is outputted as a results file by a separate piece of software. The number of tabs is likely to be different each time I import this. I am interested in only a few 'types' of the tabs in this spreadsheet and these always end in "_Main" (the tabs not of interest do not end in "_Main". Ultimatey I want a script that can import these spreadsheets, identify the tabs of interest and then add a couple of columns (multiply a couple of the other existing columns), with which I am hoping to create some graphs from.
So far I have been able to bring in the data using the following:
mydata = importdata('Test1.xlsx');
When I open the data in the workspace, the data has several subheadings (data, textdata, colheaders). Within the 'data' section of this, I can see the various tabs from my spreadsheet (some with "_Main" in the title and some without). Then I have identified the tabs of interest and output them in a separate array called "g". I have done this via the following:
for i=1:numel(fnames)
if contains(fnames(i), "Main")
bingo(i) = 1 ;
else bingo(i) = 0 ;
end
end
Target=find(bingo) ;
for counter2=1:numel(Target)
TempValue1 = Target(1,counter2)
g(TempValue1,1)= fnames(TempValue1,1)
end
However, my problem is now that I am not sure how I can call up those identified tabs. I can call this up from the command window as:
mydata.data.EXAMPLE_Main
But is there a way I can codify this? e.g can I call up mydata.data.<the 2nd tab> ?
Thanks,
Chris
CHRIS HARRISONhttps://fr.mathworks.com/matlabcentral/profile/authors/11518499tag:fr.mathworks.com,2005:Question/7659812021-03-08T09:33:46Z2021-03-08T09:58:36ZIs there a uniquetol for tables?Is there a function working just like uniquetol which accepts tables as input argument?Krystianhttps://fr.mathworks.com/matlabcentral/profile/authors/475100tag:fr.mathworks.com,2005:Question/7655112021-03-07T17:35:22Z2021-03-08T09:56:45ZHow could I match data from two files?I have two .txt files. The first column of a FILE 1 contains some of the strings/ names that also exist in the first column of the FILE 2. In FILE 2 for each item / name corresponds a number in the same order. I want for each element of the first column of file 1 to find the number of column 2 of file 2.
[For example I want the first cell of FILE1 ("B") to correspont to number 56 of FILE2 etc - I am uploading these files]
Could you please help me ?
I am importing also the final file I want to create (FINAL.txt)Ivan Michhttps://fr.mathworks.com/matlabcentral/profile/authors/15708342tag:fr.mathworks.com,2005:Question/7653462021-03-07T12:46:45Z2021-03-08T09:55:04Z¿Hoy can I plot two graphs at once (together) keeping them separate (next to one another)?I want to create a graph consisting of 2 graphs where each of them is a quadrant. These 2 graphs I already got them, but I dont know how to tell matlab to plot them next to one another creating a global graph. The first graph represents the left quadrant, the second one represents the right quadrant. I want the resulting "global" graph.Vicente Fernández Rodillahttps://fr.mathworks.com/matlabcentral/profile/authors/18690050tag:fr.mathworks.com,2005:Question/7660162021-03-08T09:54:48Z2021-03-08T09:54:48ZResponse to an impulse(delta dirac)This is my question there is a spring mass damper system.....hit by an impulse at t=0 for magnitude for 2 sec.....I know the logic by I dont know how to execute the delta dirac in ode45
f = @(t,x) [x(2) ; 0.2*(20*dirac(t)-20*dirac(t-2)-10*x(2)-2000*x(1))]; %% the second dirac cancelling the 1st after 2sec
op = odeset('Reltol',1e-7,'Abstol',1e-7);
[t,xa] = ode45(f,[0 10],[0 0],op); %% initial condition are 0
plot(t,xa(:,1),'Linewidth',1.5) %% Plot
xlabel('t'), ylabel('x')
grid on;
hold on
Shubhamhttps://fr.mathworks.com/matlabcentral/profile/authors/19332031tag:fr.mathworks.com,2005:Question/7653262021-03-07T12:17:56Z2021-03-08T09:53:55ZFind intersection between two curvesHello i have plot two curves and i would like to create a function so as to find the intersections between the two curves
Here is my code :
x=-100*pi:pi/32:100*pi;
y1=exp(x);
y2=sin(x);
figure(1)
plot(y1,'b');hold on
plot(y2,'g');
hold off
gridAkash Gooljarhttps://fr.mathworks.com/matlabcentral/profile/authors/21434611tag:fr.mathworks.com,2005:Question/7655362021-03-07T17:48:39Z2021-03-08T09:52:15ZError using horzcat Dimensions of arrays being concatenated are not consistent.clc;
close all;
No_Users=1000;%number of symbols
Radius_Ini=0;
Azimuth_Angle=5;
Beta_tilt=60;
Spa_Angle=2;
No_Cell=3;
No_Orth_Pilots=100;
Ant_Gain=10;
Total_Ant=128;
Eb_No=1:1:No_Orth_Pilots;
Signal_to_Noise_Ratio=Eb_No+10*log10(2);
active_Pilots=randsrc(1,No_Orth_Pilots*No_Users,[-1 1]);
Passive_Pilots=1/sqrt(2)*(randsrc(1,No_Orth_Pilots*No_Users,[-1 1])+1i*randsrc(1,No_Orth_Pilots*No_Users,[-1 1]));
active_pilot_grouping=reshape(active_Pilots,No_Orth_Pilots,No_Users).';
Passive_pilot_grouping=reshape(Passive_Pilots,No_Orth_Pilots,No_Users.');
Active_Pilot_Assignment = [zeros(No_Users,(Beta_tilt/Ant_Gain)) active_pilot_grouping(:,(1:No_Orth_Pilots/Spa_Angle)) zeros(No_Users,No_Cell) active_pilot_grouping(:,( No_Orth_Pilots/Spa_Angle+1:No_Orth_Pilots )) zeros(No_Users,Azimuth_Angle)];
Active_Pilot_Assignment_Combined = [zeros(No_Users,(Beta_tilt/Ant_Gain)) Passive_pilot_grouping(:,(1:No_Orth_Pilots/Spa_Angle)) zeros(No_Users,No_Cell) Passive_pilot_grouping(:,(No_Orth_Pilots/Spa_Angle+1:No_Orth_Pilots)) zeros(No_Users,Azimuth_Angle)];SHAIK SHAHNAZ BEGAMhttps://fr.mathworks.com/matlabcentral/profile/authors/13552657tag:fr.mathworks.com,2005:Question/5171412020-04-11T15:22:34Z2021-03-08T09:51:21ZUse MATLAB to write a code (m-file) to sample the signal:: x(t) = 4cos(200πt), at sampling frequency equal to 400 Hz and then to plot the sampled signal x[n], consider 10 cycles of x(t). …………………………………………………………………………………………Yasir Ammarhttps://fr.mathworks.com/matlabcentral/profile/authors/17760922tag:fr.mathworks.com,2005:Question/7660012021-03-08T09:40:21Z2021-03-08T09:48:26ZHow Live script embedded in ppt?Hi,
I would like to know if it is possible to put dynamic live script in ppt or connect online matlab to ppt (or other programs) in order to show dynamic live scripts during a presentation without exiting ppt.
thanksGiorgia Fattorinihttps://fr.mathworks.com/matlabcentral/profile/authors/9685999tag:fr.mathworks.com,2005:Question/3958952018-04-18T19:44:13Z2021-03-08T09:46:28ZHow can I get a loop to process all ".avi" files in a folder, then produce the corresponding ".txt" and ".png" file?I am creating a deep learning CNN with Python and Tensorflow, but the information that will be used in the network will be processed in MATLAB, and so my task is as follows:
I am to use MathWorks' sample code for MotionBasedMultiObjectTracking, but modify it in such a way that as it tracks a moving object, such as a person, in a supplied '.avi' file, it retrieves the (x,y) coordinates of the centroid of the bounding box as it moves in each frame, and writes that information to a '.txt' file. While it does this, it should also print a pattern of white dots onto an all black image, which represents the centroid/(x,y) coordinates as they change across each frame, and save the resulting image as a '.png' file.
I already have this part but that information was supplied just to provide a better understanding of what I'm trying to accomplish overall. Now my problem is that I can't figure out how to write a function or script that can go through all of my .avi files and produce the corresponding x,y coord .txt file and dot pattern .png file. Here is some code:
function MotionBasedMultiObjectTrackingExample()
% create a white image
imageTraj = 255 * ones(480, 640, 'uint8');
blackTraj = 0 * imageTraj;
% create a file to save trajectory data
fileID = fopen('Pattern 1-1.txt','w+');
%imshow(image);
% Create System objects used for reading video, detecting moving objects,
% and displaying the results.
obj = setupSystemObjects();
tracks = initializeTracks(); % Create an empty array of tracks.
nextId = 1; % ID of the next track
% Detect moving objects, and track them across video frames.
while ~isDone(obj.reader)
frame = readFrame();
[centroids, bboxes, mask] = detectObjects(frame);
predictNewLocationsOfTracks();
[assignments, unassignedTracks, unassignedDetections] = ...
detectionToTrackAssignment();
updateAssignedTracks();
updateUnassignedTracks();
deleteLostTracks();
createNewTracks();
displayTrackingResults();
end % end of while
fclose(fileID);
saveas(gcf,'Pattern 1-1.png');
%open the generated image for dilation
BW = imread('Pattern 1-1.png')
%dilation function(strel('dilation type', dilation_strength))
SE = strel('square', 8);
%actually perform the dilation and show the new dilation image
BW2 = imdilate(BW,SE);
figure,imshow(BW2), title('Dilated')
%resize the dilated image
BW3 = imresize(BW2, [64 64]);
figure, imshow(BW3), title('Resized and dilated')
saveas(BW3,'resizedBW3.png');
%% Create System Objects
% Create System objects used for reading the video frames, detecting
% foreground objects, and displaying results.
function obj = setupSystemObjects()
% Initialize Video I/O
% Create objects for reading a video from a file, drawing the tracked
% objects in each frame, and playing the video.
% Create a video file reader.
%obj.reader = vision.VideoFileReader('udcvideo.mp4.mp4');
obj.reader = vision.VideoFileReader('Scenario 1-1.avi');
% Create two video players, one to display the video,
% and one to display the foreground mask.
obj.maskPlayer = vision.VideoPlayer('Position', [740, 400, 700, 400]);
obj.videoPlayer = vision.VideoPlayer('Position', [20, 400, 700, 400]);
% Create System objects for foreground detection and blob analysis
% The foreground detector is used to segment moving objects from
% the background. It outputs a binary mask, where the pixel value
% of 1 corresponds to the foreground and the value of 0 corresponds
% to the background.
obj.detector = vision.ForegroundDetector('NumGaussians', 3, ...
'NumTrainingFrames', 40, 'MinimumBackgroundRatio', 0.7);
% Connected groups of foreground pixels are likely to correspond to moving
% objects. The blob analysis System object is used to find such groups
% (called 'blobs' or 'connected components'), and compute their
% characteristics, such as area, centroid, and the bounding box.
obj.blobAnalyser = vision.BlobAnalysis('BoundingBoxOutputPort', true, ...
'AreaOutputPort', true, 'CentroidOutputPort', true, ...
'MinimumBlobArea', 400);
end % end of setupSystemObjects()
My videos are named in the folder as follows: Scenario 1-1 to 1-10, Scenario 2-1 to 2-10.... Scenario 10-1 to 10-10. So there's 100 '.avi' files in the folder. In the setupSystemObjects() function, I supply the video file reader with 'Scenario 1-1.avi'. When I run the program, it runs the process on Scenario 1-1.avi, produces Pattern 1-1.txt, and Pattern 1-1.png, just like I want. The big question is how can I loop it, updating the file name each time so that every time the function is called, it will move to the next file, let's say 'Scenario 1-2.avi' for example, and produce the respective .txt and .png files, all the way until it has finished with the 100 videos in the folder.
I have developed this loop but I'm not sure how to proceed from here: (The comments on the inside below 'code would go here' was just me trying different things.
function FileExample()
d = uigetdir('','Select Input-folder'); %select the input-folder that contains the subfolders
cd(d);
list = dir;
list = list([list.isdir]);
list = list(~ismember({list.name},{'.' '..'}));
l=length(list);
for i=1:l
oldfolder = cd(list(i).name);
% Perform your operation on the files, e.g., if you are working with avi files
files = dir('*.avi');
numberOfFiles = length(files);
for k = 1:numberOfFiles
% code would go here
%
% file name files(k)
% MotionBasedMultiObjectTrackingExample( files(k) )
end
cd(oldfolder);
end
endTevin Galeshttps://fr.mathworks.com/matlabcentral/profile/authors/12419132tag:fr.mathworks.com,2005:Question/7660112021-03-08T09:45:21Z2021-03-08T09:45:21ZExcel file generate function using import data errorHi,
I'm very new to Matlab and have to use the import data generate function to import an excel file with multiple sheets.
However when I try to create this function it comes up with a long function and when I run it, I receive an error:
Not enough input arguments.
Error in importfile3 (line 25);
if nargin == 1 || isempty(sheetName)
This is the beginning of the script:
%% Input handling
% If no sheet is specified, read first sheet
if nargin == 1 || isempty(sheetName)
sheetName = 1;
end
% If row start and end points are not specified, define defaults
if nargin <= 2
dataLines = [3, 22];
end
I have no idea how to fix this problem and could really use some help.jose van der sandenhttps://fr.mathworks.com/matlabcentral/profile/authors/21315231tag:fr.mathworks.com,2005:Question/7660062021-03-08T09:44:33Z2021-03-08T09:44:33ZCompose High Level Synthesis (HLS) from Matlab codeHi,
Is it possible to compose HLS from matlab code. And how to do so?
NOORAISYAH NABILAHhttps://fr.mathworks.com/matlabcentral/profile/authors/18704981tag:fr.mathworks.com,2005:Question/7659962021-03-08T09:39:10Z2021-03-08T09:39:10ZFinding the corresponding combination of values for a given outcomeI have created this code to calculate the thickness and camber of an airfoil by measuring two points (y1 and y2) in the upper and lower surface (z_airfoil is the surface). My desired output is a combination of values of "a" and "b" that give me the desired thickness(trel1,trel2,trel3) and camber(hmax1,hmax2). I need 6 pairs of values of "a" and "b" as I want to compare the thickness_rel and camber values I measured with: trel1 and hmax1, trel2 and hmax1, trel3 and hmax1, and the same combination with hmax2. I don't know how to get this as I get confused when it comes to the indices inside the for loops. Could someone help me figuring out this?
% Input data (assumed)
a = 0:0.1:1;
b = 0:0.1:1;
% Desired relative thickness and camber
trel1 = 0.08; % 8%
trel2 = 0.14; % 14%
trel3 = 0.25; % 25%
hmax1 = 0; % 0%
hmax2 = 0.08; % 8%
%Flow along contour of Circle and Joukowsky Airfoil
theta1 = pi:-0.01:0; %radians
theta2 = pi:0.01:2*pi;
for j=2:length(a)
for k=2:length(b)
c(j,k) = -a(j) + sqrt(d^2-b(k)^2);
%Up surface
for i=1:length(theta1)
R_up(i,j,k) = -(a(j)*cos(theta1(i))-b(k)*sin(theta1(i))) + sqrt((a(j)*cos(theta1(i)))^2-(2*(a(j)*cos(theta1(i)))*(b(k)*sin(theta1(i))))+(b(k)*sin(theta1(i)))^2+c(j,k)^2+(2*c(j,k)*a(j)));
z_circle_up(i) = R_up(i,j,k)*(cos(theta1(i))+1i*sin(theta1(i)));
z_airfoil_up(i) = z_circle_up(i)+c(j,k)^2/z_circle_up(i);
x1(i)=real(z_airfoil_up(i));
y1(i)=imag(z_airfoil_up(i));
end
%Down surface
for i=1:length(theta2)
R_down(i,j,k) = -(a(j)*cos(theta2(i))-b(k)*sin(theta2(i))) + sqrt((a(j)*cos(theta2(i)))^2-(2*(a(j)*cos(theta2(i)))*(b(k)*sin(theta2(i))))+(b(k)*sin(theta2(i)))^2+c(j,k)^2+(2*c(j,k)*a(j)));
z_circle_down(i) = R_down(i,j,k)*(cos(theta2(i))+1i*sin(theta2(i)));
z_airfoil_down(i) = z_circle_down(i)+c(j,k)^2/z_circle_down(i);
x2(i)=real(z_airfoil_down(i));
y2(i)=imag(z_airfoil_down(i));
end
%Measuring the distance
l(j,k) = 4*(a(j)+c(j,k))^2/(2*a(j)+c(j,k)); %chord
thickness_rel = max(abs(y2-y1))./l;
camber = max(abs(0.5*(y2+y1)))./l;
end
endMaria Sarcoshttps://fr.mathworks.com/matlabcentral/profile/authors/17943360tag:fr.mathworks.com,2005:Question/7659862021-03-08T09:34:38Z2021-03-08T09:34:38ZSpeed control and Position of DC motor using PID and SimscapeHello everyone. I was wondering if anyone would know how I can ,starting from this DC motor layout, design on the one hand a speed control for this motor.
Thank you very much
Alejandro Fernándezhttps://fr.mathworks.com/matlabcentral/profile/authors/14262385tag:fr.mathworks.com,2005:Question/7659762021-03-08T09:33:42Z2021-03-08T09:34:35ZHelp a newbie: Applying Majority Voting to CNN ModelsI have 5 CNN models, trained from the images datastore with predictions
Predictions = [cnn1,cnn2,cnn3,cnn4,cnn5];
Please how can I apply majority voting to this?Ola Olahttps://fr.mathworks.com/matlabcentral/profile/authors/17520120tag:fr.mathworks.com,2005:Question/7625062021-03-04T08:15:23Z2021-03-08T09:32:41ZStudent MathLab activation failed I have installed student MatLab 2018b. Before i was trying to run 2019a, but there was an error all the time. Now i can not even activate the program. It's writing- activation is complete, but it asking to activate again. My computer user name is absolutely the same with my username on MathWorks. I even downloaded licence file from MathWorks and tried to activate in offline modus. Same problem. Mikita Arabeihttps://fr.mathworks.com/matlabcentral/profile/authors/21725358tag:fr.mathworks.com,2005:Question/7616812021-03-03T14:17:22Z2021-03-08T09:31:37ZQuestion regarding DDPG PMSM FOC control exampleTrying to do PMSM control similar to the DDPG model used but I have modelled the motor in terms of dq frame(vd, vq as input, id,iq,speed as output).
Is there a need to discretize the entire environment with different sampling times and use IIR filters if I am not going to use PWM? Or does the DDPG agent require the environment to be discrete?Mohamed Hannan Sohailhttps://fr.mathworks.com/matlabcentral/profile/authors/20867648tag:fr.mathworks.com,2005:Question/7657262021-03-07T23:39:44Z2021-03-08T09:31:17ZReconstruct 2D cross-section (top-view) from multiple x-ray images (side-view)Hi there.
I have some images of x-ray taken from multiple angles (e.g., 0, 30, 60, 90, 120, and so on). The x-ray is side-view. I want to reconstruct the cross-section image (top-view). Does anyone knows MATLAB code for doing this?
Thanks
Abdul
Abdul Kadir Alhamidhttps://fr.mathworks.com/matlabcentral/profile/authors/17124326tag:fr.mathworks.com,2005:Question/7636812021-03-05T09:09:28Z2021-03-08T09:30:52ZAntenna radiation pattern rotationHello everyone,
I'm having some problems with a rotation of the antenna field. Here my antenna pattern now, after a decomposition of the theta and phi fields in x,y,z-ones:
and I'd like to rotate the main lobe along the x-axis. Do you have any idea to how I shoud do it? (without the phased array toolboox - so the rotpad function- because I do not have the toolboox).
I tried applying the matrix rotation on the 3(x,y,z)-components but it just gives me a kind of "change of name". Here the results:
But as you can see the main lobe is now in the z-component (right for my purpose) but not along the x-axis.
Thank you a lot in advance.
Marina Lottihttps://fr.mathworks.com/matlabcentral/profile/authors/8123894tag:fr.mathworks.com,2005:Question/7659712021-03-08T09:30:33Z2021-03-08T09:30:33Zhow to access .cdf fileHello,
I am using matlab R2020a in windows 10 pro.
I have downloaded data from (/mms/sdc/public/data/mms1/fgm/brst) data science centre and i want to open it.
I am using data = cdfread(); syntax for this purpose as given in the matlab documentation but error is occuring as,
"Error using cdfread (line 149). Unable to open file. File might be corrupt or filename might have unsupported characters."
Similarly If I use [data,info] = cdfread();, the error occuring is as follows:
"Error using cdflibmex
33 is not a recognized DATATYPE mode.
Error in cdflib.inquireVar (line 28)
[name,dtype,nelts,dims,recVary,dimVary] = cdflibmex('inquireVar',cdfId,varNum);
Error in cdfread>read_data_by_hyperslab (line 357)
varinfo = cdflib.inquireVar(cdfid,varnum);
Error in cdfread>read_data (line 209)
data = read_data_by_hyperslab(cdfid,options);
Error in cdfread (line 172)
data = read_data(cdfid,options);"
Please help me out with this issue, if possible!
neetasha aryahttps://fr.mathworks.com/matlabcentral/profile/authors/20831014tag:fr.mathworks.com,2005:Question/7659062021-03-08T08:04:42Z2021-03-08T09:27:17ZHow to show 1e-10 in plot? my y axis range is 1e-10 to 0.1.I want to create a plot like below:
I try code blow:, but it doesn't work
y =[0.5, 0.1, 1e-2, 1e-3, 1e-4, 1e-5, 1e-6]
x = [0, 5, 5*2, 5*3, 5*4, 5*5, 5*6]
plot(x, y, 'rx', 'MarkerSize', 10); % Plot the data
ylim([1e-15,1])
ylabel('variance'); % Set the y−axis label
xlabel('iteration');
the plot like this:
Hongjin Wanghttps://fr.mathworks.com/matlabcentral/profile/authors/15102500tag:fr.mathworks.com,2005:Question/7659662021-03-08T09:27:02Z2021-03-08T09:27:02ZHow to add additional rows to uitable?I have (X,Y) vextor pairs for storing spectral data. If someone wants to correct the vectors I make an uitable user input, where users can correct, replace etc. the data they have (uitable has two columns). Is there any easy way to add new rows (or columns??) to the existing uitable if the user wants to add some extra data not just correct the existing data?
I think it should be possible because in the variable window you can easily change the size of a variable just using the matrix where the variable is written, simply put a number to any matrix element. The variable size will immediately change and the missing values would be filled by zero. I would like to have something similar.Csabahttps://fr.mathworks.com/matlabcentral/profile/authors/512047tag:fr.mathworks.com,2005:Question/7659412021-03-08T08:47:46Z2021-03-08T09:26:20ZDynamic modeling of Lithium-ion battery Hello,
I am going to obtain dynamic model of Li-ion battery and then compare my model to that one existed in matlab. There is a battery block in this directory,
Simscape / Electrical / Specialized Power Systems / Electric Drives / Extra Sources
I am so thankful if you let me know the model which Matlab has been used is a Dynamic model or not.
Apparently there is no RC circuit. But, the model acts precisly.
Sincerely Mohammadhttps://fr.mathworks.com/matlabcentral/profile/authors/5679599tag:fr.mathworks.com,2005:Question/7659612021-03-08T09:24:37Z2021-03-08T09:25:39ZHow to have a stack plot with different colors?I have the following stacked plot that I want to change the color of but I am unable to do so. Thanks in advance.
Jay Vaidyahttps://fr.mathworks.com/matlabcentral/profile/authors/16218757tag:fr.mathworks.com,2005:Question/2494112015-10-19T06:49:55Z2021-03-08T09:25:34ZCombining N pattern classifiers using weighted majority voting in MatlabI want to combine some classifiers. The number of classifiers is 4 and there are 3 possible classes. I came a cross this code: "Efficient multiclass weighted majority voting implementation in MATLAB". It makes use of 3 classifiers and 3 possible classes. I have tried to customize it for use with 4 classifiers and 3 possible classes without success. How can this code be extended for use in my case, or to N classifiers. Or is there any other code applicable to my case. Please help.
daniel osutohttps://fr.mathworks.com/matlabcentral/profile/authors/6261422tag:fr.mathworks.com,2005:Question/7587342021-02-28T18:16:14Z2021-03-08T09:19:56Zhow to share the data from one app to another app in matlab app designer I know this question already asked I also going to refference document but the concept is not cleard to me.
please help me to reach out. I explained below what I want.
I have User input promt on which i taken the input as temperature value in 3 numeric EditFeild.
share that 3 numeric edit feild value to another app where another 3 numeric EditField in that I want to show average of all the temperature, maximum and minimum temperature among three .
I have added 1st button to open the 2nd app and 2nd button to get the result in other app.
I think this enough to clear the concept how to share the data from one app to another.
please suggest code for it thank you! Krutik Gujarathihttps://fr.mathworks.com/matlabcentral/profile/authors/18541524tag:fr.mathworks.com,2005:Question/7630612021-03-04T16:40:00Z2021-03-08T09:19:51ZNeed to calculate the power of batteryHello there,
Please kindly help me to write the matlab function code to calculate the power of the battery. Actually, the problem is that I have the I have a cost function whose output is battery power and there are several inputs. But the equation to calculate the input variables also depend on the output of previous time which is currently unknown. I can give you some example here:
function [X(t)]=batterypower(a(t)+b(t)+c(t)+d(t))
a(t)=b(t-1)+c(t-1)/X(t-1);
b(t)=a(t-1)/d(t-1);
c(t)=X(t-1)-d(t-1)/a(t-1);
d(t)=c(t-1)*b(t-1)/a(t-1)
where t=0:100 %time
I used for loop but still cannot get the result.
This is just the example but my problem is also similar. As we can see the input variable also depend on past output variable which is not yet calculated. How can write this in matlab function code. If anybody can help me, please I would be very thankful to him/her.
If you require my equation and given data, I would share that too. Please help me. Ajit Bashyalhttps://fr.mathworks.com/matlabcentral/profile/authors/18599455tag:fr.mathworks.com,2005:Question/7658462021-03-08T06:02:11Z2021-03-08T09:18:04ZPlot not disappearing when using STOP button and visible offfunction pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%handles.stop_now=1;
%guidata(hObject, handles);
set(handles.pushbutton3,'userdata',1)
set(handles.axes4,'visible','off');
I have created pushbutton to stop the programme. Simultaneously it should make the plot in handles.axes4 invisible. However the axes get invisbile put plot remains. How to rectify the sameAvinav Kumarhttps://fr.mathworks.com/matlabcentral/profile/authors/12460641tag:fr.mathworks.com,2005:Question/7629312021-03-04T14:42:10Z2021-03-08T09:12:04ZHow to establish shh from Matlab (or how to start programm on remote computer by sending the matlab command on Windows)For my experiment I need to send the command from matlab (which is running on windows) to the linux (running on the remote computer).
The first idea was to use putty and to find the way how to send the command from matlab to putty. But I found no solution for this problem.
In matlab community I found ssh2 function which is looking useful. But if I put in the command window
ssh2_simple_command('username@name_of_pc','username',passwort','ls -la *ninjas*')
I receive an error “SSH2 could not connect to the ssh2 host - ‘username@name_of_pc'.
I would be very grateful if you could give me an advice, how to solve this problem.
Many thanks in advanceInna Forsiukhttps://fr.mathworks.com/matlabcentral/profile/authors/20196838tag:fr.mathworks.com,2005:Question/7659562021-03-08T08:56:42Z2021-03-08T08:56:42ZHow to store multi images like a tensor?Hi everybody,
I have 50 images, each with size m * n. I want to store it as a tensor. has dimensions (m * n) x 50. Like a video.
please help me.lehuydiphttps://fr.mathworks.com/matlabcentral/profile/authors/10561530tag:fr.mathworks.com,2005:Question/7659512021-03-08T08:52:42Z2021-03-08T08:52:42ZMatlab code required for equations
These are 3 equations that form a 2/2 matrix which is symmetric for N=1 P=1
Q = [Q00 Q01;
Q10 Q11; ];
I want to verify and then write a generalized matlab code that gives these results
Q00= I + Iy2*cos(th2)^2 + Ix2*sin(th2)^2 + m2*r02^2*cos(th2)^2 + m2*r02^2*sin(th2)^2 + m2*r2^2*sin(th2)^2
Q01=Q10= Iyz2*cos(th2) + m2*r02*r2*cos(th2)
Q11= m2*r2^2 - g*m2*sin(th2)*r2 + Iz2
I wrote the first code for Q00 by editing the equation a bit:
clear all
close all
clc
P=1;
N=1;
syms Ix [1 N+1]
syms Iz [1 N+1]
syms Iy [1 N+1]
syms Iyz [1 N+1]
syms th [1 N+2] % as starts from th2 as in--> Ix2*sin(th2)^2
syms r0 [1 N+1];
syms r [1 N+1];
syms l [1 N+1];
syms g I
syms m [1 N+1];
syms n [1 N]
syms xx [1 N-1]
syms aa [1 N]
syms P1 [1 P]
for mm=1:N
aa(mm)=sin(th((mm+1)))
end
sum(aa(1:N));
bb=sum(aa(1:N)); % bb=sin(th2)
if N ~=1
for n=1:N-1
xx(n)=l(n+1);
end
ww=(sum(xx(1:N-1))); % N=2 ww=l2
else
ww=1 % Added this condition as l1 values are neglected for N=1
end
%------------------------------------------------------------------
%MAIN LOOP
for N=1:P
P1(N) =Iy(N+1)+(((r0(N+1)).^2)*m(N+1))+((Ix(N+1)-Iy(N+1))*(sum(sin((th(2:N+1))))).^2)+((m(N+1)*(r(N+1)).^2*((ww*(bb)).^2)));
end
Q00=I+sum(P1(1:P))
expand((Q00))
It correctly gives the Q00 value as above - hence verified.
CAN SOMEONE HELP WRITE THE CODE FOR EQUATION 2 and 3 for
Q01/Q10 and Q11amena zainabhttps://fr.mathworks.com/matlabcentral/profile/authors/19755389tag:fr.mathworks.com,2005:Question/7615312021-03-03T12:04:40Z2021-03-08T08:52:08ZInstallation path is not accessibleRunning a Kubuntu 20.04,
sudo chown -R $USER /usr/local/MATLAB/R2020b
does not solve the problem. Any ideas?
Toolbox: https://petercorke.com/toolboxes/robotics-toolbox/Mathias Mettauerhttps://fr.mathworks.com/matlabcentral/profile/authors/9997535tag:fr.mathworks.com,2005:Question/7659462021-03-08T08:49:25Z2021-03-08T08:49:25ZHow to conduct octave analysis on frequency domain siganal?Hi guys,
Maybe it is a silly question, but I want to calculate 1/3 octave analysis on an already frequency domain signal stored as a vector in MATLAB. I know how to calculate the center frequencies and the upper and lower frequuency bounds. What I'm not sure about is the value of the octave bands. Should I just average the values of the spectrum of the signal between lower and upper bounds? How does this work?Csanad Levente Baloghhttps://fr.mathworks.com/matlabcentral/profile/authors/12690710tag:fr.mathworks.com,2005:Question/7659362021-03-08T08:47:42Z2021-03-08T08:47:42ZCan I use this algorithm with GPU coding?I want to create code about picture and want to do monte carlo simulation with gpu
Is it possible to code with gpu?
1st pseudo code
Function EvaluateTopEventProbability (T)
//for number of samples n
For number of samples n
//determine the state of events
For each Ei which is a basic event
//a random number r between 0 and 1
r = rand()
//State of Ei
if r ≤ Pi then Si = True else Si = False
//Calculate the state of top event
ST = GetState (T)//f(S)
if ST ≡ True then m = m + 1
//Evaluate the top event probability PT
PT = m/n
Return PT
2nd pseudo code
Function GetState (g)
//return Sg for basic event
if g is a basic event then
return Sg
//for Gate
//if already processed
if Sg is already determined then
return Sg
//calculate the state for each input
For each Ci ∈ g
//recursively for each input
Si = GetState (Ci)
//Determine the State of g
Sg = DetermineState (g)
Return Sg
3rd pseudo code
Function DetermineState (g)
if g is a OR Gate then
u = False
For each Ci ∈ g
u = u∪Si
else if g is a AND Gate then
u = True
For each Ci ∈ g
u = u∩Si
else if g is a NOT Gate then
For Ci ∈g
u = not Si
Sg = u
return Sgjaehyun yuhttps://fr.mathworks.com/matlabcentral/profile/authors/7827142tag:fr.mathworks.com,2005:Question/7639312021-03-05T13:13:22Z2021-03-08T08:45:29ZHow to generate multiple random combinations of word pairs with specific restrictions on avoiding repetition?I want to randomly combine word pairs such that I can generate an instruction - e.g., "Spin yellow rubber".
Actions={'spin',
'pick up',
'push',
'touch',
'shake',};
Objects={'yellow rubber',
'white rubber',
'pink ruler',
'blue ruler',
'orange folder',
'green folder',
'purple bag',
'brown bag',
'gold box',
'black box',
'red pencil',
'grey pencil'};
2. I'd like to expand this to generate a sequence of 4 instructions - e.g., "spin yellow rubber, pick up pink ruler, push orange folder, touch gold box'. I want to generate 192 sets of four-sequence instructions [192 x 4].
3. I don't want repetitions of the action AND the object within the sequence of 4 instructions. In my 192 x 4 instructions, I do not want the instruction (e.g., spin yellow rubber) to appear in two consecutive rows.Abi Fiskehttps://fr.mathworks.com/matlabcentral/profile/authors/16661776tag:fr.mathworks.com,2005:Question/7638862021-03-05T12:30:04Z2021-03-08T08:45:29ZIs there a way to relate colorbar values to geodensityplot weight?I am trying to relate the values of my geodensityplot to the colorbar.
The values in the colorbar range from 0 to 2.5 x 10^-8.
The weight values in my geodensityplot range from 1 - 11.
How can I make the colorbar values correspond to my weight values?
I know that I could replace the colorbar values with Tick Labels but I'm uncertain of the relationship between colorbar colors/values and my geodensityplot weight data.
Sample code.
%% GeoDensityPlot of GPS grid weighted by number of Cell Towers within Range
figure(1)
geodensityplot(inRangeGridAll(:,1),inRangeGridAll(:,2),inRangeGridAll(:,3),'FaceColor','interp');
geobasemap('darkwater')
colorbar
%Annotations
title("Cell Tower Signal Density Map")
Joseph Kovachhttps://fr.mathworks.com/matlabcentral/profile/authors/21753437tag:fr.mathworks.com,2005:Question/7659312021-03-08T08:44:46Z2021-03-08T08:44:46Zoptimization using genetic algorithm using two variable I am new to use GA, I want to implement genetic algorithm to find out the optimize variables for the maxiamum value of my Power function ,which is calculted by solving a differential equation but when I run my GA code then it gives only initial value (lower bond value) for the optimize variables. I here write my fitness function and GA function.please anyone suggest the possible mistakes in my GA code. Thanks
% fitness function
function [Fitness_fun] = tribo1(X)
R = X(1);
d = X(2);
sigma = 15e-5;
S = 22.5e-4;
epslno = 8.854e-12;
epslnr=3.4;
Ao = 5e-3;
f = 3.3;
w = 2*pi*f;
thita = 1.5*pi;
h=1e-5;
x = 0:h:0.8;
y = zeros(1,length(x));
I = zeros(1,length(x));
I(1)=0;
y(1)=0;
F_xy = @(t,Q) ((sigma/(epslno*R))*(Ao*sin(w*t+thita)+Ao)...
-Q*((d/epslnr)+Ao*sin(w*t+thita)+Ao)/(S*epslno*R));
for i=1:(length(x)-1)
k_1 = F_xy(x(i),y(i));
k_2 = F_xy(x(i)+0.5*h,y(i)+0.5*h*k_1);
k_3 = F_xy((x(i)+0.5*h),(y(i)+0.5*h*k_2));
k_4 = F_xy((x(i)+h),(y(i)+k_3*h));
y(i+1) = y(i) + (1/6)*(k_1+2*k_2+2*k_3+k_4)*h;
I(i+1)=((sigma/(epslno*R))*(Ao*sin(w*x(i+1)+thita)+Ao)...
-y(i+1)*((d/epslnr)+Ao*sin(w*x(i+1)+thita)+Ao)/(S*epslno*R));
end
V=I*R;
P=V.*I;
[Power_IND]=max(P);
Fitness_fun=1/(1+Power_IND);
end
%%
% GA code-
clc
format long g
%*********************************************************
%GA Inputs
rng default
FitnessFunction = @tribo1;
numberOfVariables = 2;
lb = [10e6 50e-6];
ub = [10e13 550e-6];
Aeq = [];
beq = [];
A = [];
b = [];
Ini_Popu = [10e6 50e-6];
NonLinFunction=[];
options = gaoptimset('PlotFcns',{@gaplotbestf,@gaplotbestindiv,@gaplotstopping,@gaplotselection},...
'PopulationSize',50,...
'Generations',10000,...
'EliteCount',2,...
'CrossoverFraction',0.8,...
'ParetoFraction',0.035,...
'MigrationDirection','forward',...
'MigrationInterval',20,...
'MigrationFraction',0.2,...
'TimeLimit',Inf,...
'StallGenLimit',100,...
'FitnessLimit',-Inf,...
'TolFun',1e-50,...
'TolCon',1e-12,...
'InitialPopulation',Ini_Popu,...
'PenaltyFactor',100);
options
[x,Fval,exitFlag,Output,population,scores] = ...
ga(FitnessFunction,numberOfVariables,A,b,Aeq,beq,lb,ub,NonLinFunction,[],options); %NonLinFunction
fprintf('The number of generations was : %d\n', Output.generations);
fprintf('The number of function evaluations was : %d\n', Output.funccount);
fprintf('The best function value found was : %g\n', Fval);
exitFlag
population
scores
min(scores)
xshyam kishor sharmahttps://fr.mathworks.com/matlabcentral/profile/authors/17666973tag:fr.mathworks.com,2005:Question/7646662021-03-06T10:59:07Z2021-03-08T08:44:14ZGenerate cell of random numbers with same size arraysHello!
I'd like to generate a 3x2 cell, whose arrays are all matrices 5x100 of random numbers.
I am a bit struggling with it, despite I think is quite easy to do.
Any suggestion?
ThanksRiccardo Zabattahttps://fr.mathworks.com/matlabcentral/profile/authors/16761799tag:fr.mathworks.com,2005:Question/3799292018-01-31T06:51:34Z2021-03-08T08:43:13ZHow to generate a set of N mutually orthogonal (N being a power of 2) N-dimensional binary vectors [+1,-1]? For instance:
with N=2 we could have [1 1; 1 -1]
with N=4, we could have [1 1 1 1; 1 1 -1 -1; 1 -1 1 -1; 1 -1 -1 1]
How to efficiently generate N mutually orthogonal binary vectors for larger N (8,16,32,64,...,4096,...)?Shlomo Gevahttps://fr.mathworks.com/matlabcentral/profile/authors/42583tag:fr.mathworks.com,2005:Question/7622962021-03-04T00:37:55Z2021-03-08T08:41:30ZPlotting a Fourier Sine SeriesNeed help plotting the following fourier sine series
f(z) = sum((-12/4n+2)(n*pi*z/L))
i think L can be assumed as 1 Will Jeterhttps://fr.mathworks.com/matlabcentral/profile/authors/13962327tag:fr.mathworks.com,2005:Question/7640062021-03-05T14:48:50Z2021-03-08T08:38:27ZReadability of matlab code Hi,
I am coding using matlab and have many functions, some of which have more than a dozen input arguments. The majority of the input arguments of my different functions are variables that I read from an external file and that remain unchanged all throughout the calculations. Basically I read the external file once in my main script then give what has been read as input arguments to the other functions. For the readability of my code, I would like to not have that many input arguments and was wondering what is the best solution that would not negatively impact the performance of my code. I thought of the following:
use global variables, however I've read that it is best to avoid them
read the external file and save the different variables as .mat then load the arguments inside each function
define a cell variable in which I store all my arguments, e.g. cell={a;b;c} and give that as an input to my functions, then inside the function declare the variables as a=cell{1} etc
If anyone could help me choose the best solution or give me more ideas I would greatly appreciate it!AMhttps://fr.mathworks.com/matlabcentral/profile/authors/13811912tag:fr.mathworks.com,2005:Question/7477322021-02-17T09:14:11Z2021-03-08T08:37:55ZSaving a plot as png 224*224*3 imageHi,
I have generated a plot in Matlab as shown in figure.When i save it using 'saveas(gcf,'im1.png')' , it is saved as a 656*875*3 png image.I want to save it as 224*224*3 png image without the axis titles,labelling and colorbar.i.e.only the actual plot.Can anyone kindly guide on it?
guide about
Thanksalihttps://fr.mathworks.com/matlabcentral/profile/authors/5482129tag:fr.mathworks.com,2005:Question/7659212021-03-08T08:29:37Z2021-03-08T08:34:12ZExtract only odd rows in a matrixHi, how would I modify the following code if I only want to extract the odd rows in the output matrix. The output is generated by ODE45 and I am referring to the third variable. I have already tried to use the matrix indexing in matlab but it's not working. How would I go about this? If my output is given as below?
m = y(:,3);Brilliant Purnawanhttps://fr.mathworks.com/matlabcentral/profile/authors/19525337tag:fr.mathworks.com,2005:Question/7659162021-03-08T08:22:00Z2021-03-08T08:29:11Zuse Findpeak for multiple ECG signals hey ! I am trying to use "findpeaks' for multiple ecg signals using loop.
but it does not work. I know the problem , in my file there are 30 ecg signals and every signal may have different peaks , Therefore, it is not generating a matrix having equal columns.
ecg_m has 30x 10149 rows n columns. My code is given as:
for i=1:30
[pks(i,:),locs(i,:)] = findpeaks(ecg_m(i,:));
end
Please tell me any other way to do this task. sania uroojhttps://fr.mathworks.com/matlabcentral/profile/authors/7135588tag:fr.mathworks.com,2005:Question/155332011-09-09T21:30:07Z2021-03-08T08:28:45ZObject Oriented Programming Performance Comparison: Handle Class vs. Value Class vs. no OOPI have used Matlab for many years, but have not use the object oriented programming feature until one week ago. The first thing I noticed is that Matlab OOP style is significantly different from other OOP languages such as C++ or java. The next thing I noticed is the significant performance penalty from OOP. In some extreme case, my program slows down by more than 100X, as also reported by other users.
I did several experiments. I feel I find a way to make OOP almost as fast as traditional Matlab program. Both of the observations actually have been pointed out in previous threads. I hope if some expert can confirm this.
The following is summary of my observations.
* do not call object's method in a loop. Calling the object methods involves a lot of overhead. A bad example is to call the object's method in a for loop.
*
* do not use handle class. If it does not mess up your program too much, use value class instead.
Handle class is convenient to use, but it is too slow. Reading or writing object properties, either in object method or from external, it is more than 100X slower in handle class, as shown my test 2 to 4. Something similar to the following is more than *1000X* slower in handle class
obj.b = obj.a
It is easy to understand the first one, however I am very curious about the performance difference between handle class and value class. If there is expert in this forum, could you please give some explanation on my observation?
Another question: I need to change the properties of a value class through the its method. It seems that I have to put the object as one of the return parameter, and have to call the method as the following. Is there any better way?
[obj, xout] = obj.method(xin)
*Attach one: Experiment Results*
Test 1: 100,000 times Method Call
======================================
handle class: Elapsed time is 3.302863 seconds.
value class: Elapsed time is 5.727677 seconds.
no oop: Elapsed time is 0.024743 seconds.
Test 2: 100,000 times Property Internal Access (i.e. in Method)
==============================================
handle class
style 1: Elapsed time is 0.022400 seconds.
style 2: Elapsed time is 0.039167 seconds.
style 3: Elapsed time is 1.780666 seconds.
style 4: Elapsed time is 0.039056 seconds.
no oop: Elapsed time is 0.000502 seconds.
value class
style 1: Elapsed time is 0.000255 seconds.
style 2: Elapsed time is 0.000522 seconds.
style 3: Elapsed time is 0.000242 seconds.
style 4: Elapsed time is 0.000398 seconds.
no oop: Elapsed time is 0.000503 seconds.
Test 3: 100,000 times Properties External Set
==============================================
handle class: Elapsed time is 0.022604 seconds.
value class: Elapsed time is 0.000223 seconds.
no oop: Elapsed time is 0.000189 seconds.
Test 4: 100,000 times Properties External Get
=============================================
handle class: Elapsed time is 0.011324 seconds.
value class: Elapsed time is 0.000221 seconds.
no oop: Elapsed time is 0.000220 seconds.
*Attachment two: source code*
% no oop function
function a = func_no_oop()
a = 1;
end
% handle class
classdef class_handle < handle
properties
a;
b;
end
methods
function obj = class_handle()
obj.a = 0;
obj.b = 0;
end
function assign(obj)
obj.a = 1;
end
function assignN(obj)
fprintf(1, 'style 1: ');
tic;
for ii = 1:100000
obj.a = 1;
end
toc;
fprintf(1, 'style 2: ');
tic;
for ii = 1:100000
obj.a = obj.a + 1;
end
toc;
fprintf(1, 'style 3: ');
tic;
for ii = 1:100000
obj.b = obj.a;
end
toc;
fprintf(1, 'style 4: ');
tic;
for ii = 1:100000
c = obj.a;
obj.b = c;
end
toc;
fprintf(1, 'no oop: ');
d = 1;
tic
for ii = 1:100000
d = d + 1;
end
toc
end
end
end
% value class
classdef class_value
properties
a;
b;
end
methods
function obj = class_value()
obj.a = 0;
obj.b = 0;
end
function obj = assign(obj)
obj.a = 1;
end
function obj = assignN(obj)
fprintf(1, 'style 1: ');
tic;
for ii = 1:100000
obj.a = 1;
end
toc;
fprintf(1, 'style 2: ');
tic;
for ii = 1:100000
obj.a = obj.a + 1;
end
toc;
fprintf(1, 'style 3: ');
tic;
for ii = 1:100000
obj.b = obj.a;
end
toc;
fprintf(1, 'style 4: ');
tic;
for ii = 1:100000
c = obj.a;
obj.b = c;
end
toc;
fprintf(1, 'no oop: ');
d = 1;
tic
for ii = 1:100000
d = d + 1;
end
toc
end
end
end
%Compare Script
obj_handle = class_handle();
obj_value = class_value();
disp(' ');
disp('Test 1: 100,000 times Method Call');
disp('======================================');
fprintf(1, 'handle class: ');
tic;
for ii = 1: 100000
obj_handle.assign();
end
toc;
fprintf(1, 'value class: ');
tic;
for ii = 1: 100000
obj_value.assign();
end
toc;
fprintf(1, 'no oop: ');
tic;
for ii = 1: 100000
func_no_oop();
end
toc;
disp(' ');
disp('Test 2: 100,000 times Property Internal Access');
disp('==============================================');
disp('handle class' );
obj_handle.assignN();
disp(' ');
disp('value class');
obj_value.assignN();
disp(' ');
disp('Test 3: 100,000 times Properties External Set');
disp('==============================================');
fprintf(1, 'handle class: ');
tic;
for ii = 1: 100000
obj_handle.a = 1;
end
toc;
fprintf(1, 'value class: ');
tic;
for ii = 1: 100000
obj_value.a = 1;
end
toc;
fprintf(1, 'no oop: ');
tic;
for ii = 1: 100000
a = 1;
end
toc;
disp(' ');
disp('Test 4: 100,000 times Properties External Get');
disp('=============================================');
fprintf(1, 'handle class: ');
tic;
for ii = 1: 100000
x = obj_handle.a;
end
toc;
fprintf(1, 'value class: ');
tic;
for ii = 1: 100000
x =obj_value.a;
end
toc;
fprintf(1, 'no oop: ');
tic;
for ii = 1: 100000
x = a;
end
toc;Changhua Caohttps://fr.mathworks.com/matlabcentral/profile/authors/3035992tag:fr.mathworks.com,2005:Question/7630312021-03-04T16:01:38Z2021-03-08T08:22:38ZCalibrate camera to IMU Hi all,
I would like to calculate the Extrinsic transformation matrix (rotation and translation) between camera and IMU that I have on the same board. The matrix should be 4x4 dimensions (please see image attached).
I saw that is common to use Kalibr software to this but I would like to implement this in Matlab.
Can anyone help me with this issue? Is there a code that does something like this?
Thanks,
ItaiItai Kadoshhttps://fr.mathworks.com/matlabcentral/profile/authors/10186694