https://it.mathworks.com/matlabcentral/answers/questionsMATLAB Answers — New Questions2021-01-26T15:12:52Ztag:it.mathworks.com,2005:Question/4758042019-08-12T10:37:06Z2021-01-26T15:12:52ZGet next or prior single precision value MATLAB function ?Is there a MATLAB function for next or prior float32 number ?
(similar to nextafterf, nexttowardf or float_next, float_prior)
tried these functions:
function [out] = next_SP(val)
% Get next after SP value - float32, single precision
% Increment float with smalllest step, SP representable
% TODO check for sign changes, domain INF NAN subnormals changes,
% uint32 ovf realmax + 1, mantissa exp changes
% Check nextafterf from math.h
% The nextafter() functions return the next representable floating-point
% value following x in the direction of y. If y is less than x, these
% functions will return the largest representable number less than x.
% If x equals y, the functions return y.
% https://www.boost.org/doc/libs/1_46_1/libs/math/doc/sf_and_dist/html/math_toolkit/utils/next_float/float_next.html
% Returns the next representable value which is greater than x.
% If x is non-finite then returns the result of a domain_error.
% If there is no such value greater than x then returns an overflow_error.
int_v = typecast(single(val), 'uint32' );
%disp([ 'Init ' num2str(single(val)) ' 0x' num2hex(single(val)) ', ' dec2bin(int_v, 32) ]);
int_v = int_v + 1;
out = typecast(uint32(int_v), 'single' );
%disp([ 'Init ' num2str(out) ' 0x' num2hex(out) ', ' dec2bin(int_v, 32) ]);
end
and
function [out] = prior_SP(val)
% Get next before SP value - float32, single precision
% Decrement float with smalllest step, SP representable
% TODO check for sign changes, domain INF NAN subnormals changes,
% uint32 udf realmax + 1, mantissa exp changes
% Check nexttowardf from math.h
% https://www.boost.org/doc/libs/1_48_0/libs/math/doc/sf_and_dist/html/math_toolkit/utils/next_float/float_prior.html
% Returns the next representable value which is less than x.
% If x is non-finite then returns the result of a domain_error.
% If there is no such value less than x then returns an overflow_error.
int_v = typecast(single(val), 'uint32' );
%disp([ 'Init ' num2str(single(val)) ' 0x' num2hex(single(val)) ', ' dec2bin(int_v, 32) ]);
int_v = int_v - 1;
out = typecast(uint32(int_v), 'single' );
%disp([ 'Init ' num2str(out) ' 0x' num2hex(out) ', ' dec2bin(int_v, 32) ]);
end
nexttoward_SP(-0)
Init 0 0x80000000, 10000000000000000000000000000000
Init NaN 0x7fffffff, 01111111111111111111111111111111
nexttoward_SP(0)
Init 0 0x00000000, 00000000000000000000000000000000
Init 0 0x00000000, 00000000000000000000000000000000
nexttoward_SP(-inf)
Init -Inf 0xff800000, 11111111100000000000000000000000
Init -3.402823466385289e+38 0xff7fffff, 11111111011111111111111111111111
nexttoward_SP(Inf)
Init Inf 0x7f800000, 01111111100000000000000000000000
Init 3.402823466385289e+38 0x7f7fffff, 01111111011111111111111111111111
nexttoward_SP(nan)
Init NaN 0xffc00000, 11111111110000000000000000000000
Init NaN 0xffbfffff, 11111111101111111111111111111111
(maybe similar for half or double precision)
Firan Lucianhttps://it.mathworks.com/matlabcentral/profile/authors/11849913tag:it.mathworks.com,2005:Question/7274932021-01-26T15:11:51Z2021-01-26T15:11:51ZHow to analyse performance from PID base on real dataHi,
I would like to analyse the performance of a PID controller on a drone. I don't have the model, but I have access to the command sent and the actual value of the commanded axis.
I am using Mission Planner to generate a database and extracting the data. While searching on the forum, I found the function called (stepinfo) from Matlab, but it did not gave me plausible data has seen in the Figure #1. Which bring me to my question, is it possible to analyse the performance of a PID with actual data or you need the model to find out? If you need the actual data, would it means that you need to fine tune from the data and impression of flight?
Figure #1 -- stepinfo value from the data flight
Figure #2 -- Data example for Desired Roll cmd & Actual Roll
Thank you for your help,
P.S : If this question was already asked and I miss it, please inform me and I will remove this post to avoid duplicate post.David Dozoishttps://it.mathworks.com/matlabcentral/profile/authors/18988592tag:it.mathworks.com,2005:Question/7268332021-01-25T20:59:57Z2021-01-26T15:11:41ZAppdesigner create loop for drop down ItemsHello,
I am using app designer to import data from a csv file an plot curves, based on the data from the file, in UIAxes. I'd like to implemet the function to change the colour of each curve. Therfore, I use a drop down field, filled with 8 different colours. These colours are defined in the private properties area (RGB values).
LightBlue = [0.3010 0.7450 0.9330];
DarkBlue = [0 0.4470 0.7410];
LightRed = [0.8500 0.3250 0.0980];
DarkRed = [0.6350 0.0780 0.1840];
Yellow = [0.9290 0.6940 0.1250];
Purple = [0.4940 0.1840 0.5560];
Green = [0.4660 0.6740 0.1880];
Black = [0 0 0];
After changing the dropdownfield-value, the user has to confirm his changes. To use a short code, I want to create a while-loop:
A = [app.ColourDropDown_1.Value app.ColourDropDown_2.Value app.ColourDropDown_3.Value app.ColourDropDown_4.Value app.ColourDropDown_5.Value app.ColourDropDown_6.Value app.ColourDropDown_7.Value app.ColourDropDown_7.Value];
B = [app.ColourCurve1 app.ColourCurve2 app.ColourCurve3 app.ColourCurve4 app.ColourCurve5 app.ColourCurve6 app.ColourCurve7 app.ColourCurve8];
C = 1;
while C<9
switch A(1,C)
case 'Light blue'
B(1,C) = app.LightBlue;
case 'Dark blue'
B(1,C) = app.DarkBlue;
case 'Light Red'
B(1,C) = app.LightRed;
case 'Dark Red'
B(1,C) = app.DarkRed;
case 'Yellow'
B(1,C) = app.Yellow;
case 'Purple'
B(1,C) = app.Purple;
case 'Green'
B(1,C) = app.Green;
case 'Black'
B(1,C) = app.Black;
end
C = C+1;
end
In the first iteration, the code should take the first value of matrix A (drop down field value). Then, it should take the first value from matrix B and allocate the colour-value.
Does anyone know a way to do that? I know the problem in my code, but is there another way than do the switch-case code for every chanel?
Thank you very much!Laurenz Grigathttps://it.mathworks.com/matlabcentral/profile/authors/13935768tag:it.mathworks.com,2005:Question/7269082021-01-25T23:11:11Z2021-01-26T15:10:40ZCant join 2 tables with same headers. vertcat errorCan someone explain why im getting this error? Im trying to join the rows of 2 tables who have the exact same headers, but im getting an error? Online says that vertcat or [T1;T2] should do the trick no problem, but this is not the case for me. Please help
a =
struct with fields:
id: 'a'
mode: 'read'
name: 'firstname'
type: 'double'
>> b = a
b =
struct with fields:
id: 'a'
mode: 'read'
name: 'firstname'
type: 'double'
>> b.name = 'differentfirstname'
b =
struct with fields:
id: 'a'
mode: 'read'
name: 'differentfirstname'
type: 'double'
>> Ta = struct2table(a)
>> Tb = struct2table(b)
>> [Ta;Tb]
An error occurred when concatenating the table variable 'name'
using VERTCAT.
Caused by:
Error using vertcat
Dimensions of arrays being concatenated are not consistent.
Sergio Huertahttps://it.mathworks.com/matlabcentral/profile/authors/19332182tag:it.mathworks.com,2005:Question/7274382021-01-26T13:57:03Z2021-01-26T15:09:54Zhow do i determine toolbox dependency when i try to uninstall toolbox ?When I uninstall the toolbox, Matlab doesn't seem to remind me which toolbox is dependent on another toolbox.So I want to know the dependencies between all the toolboxs.Like Global Optimization Toolbox depends on Optimization Toolbox.I need to help.Thank you.meng yuhttps://it.mathworks.com/matlabcentral/profile/authors/15287942tag:it.mathworks.com,2005:Question/7274882021-01-26T15:01:10Z2021-01-26T15:09:48ZUneven linspacing of an arrayI want to create an array with unequal spacing. I have the parameter len (of a size [1x250]) with the following values inside:
0.050077530845678 , 0.055555988803619, ...... , 1.414213562373095.
There is a constant difference between neighboring values, of 0.005478457957941.
I need to have the linspaced array with values which are spaced very densly at the begining (as my gradient there is more substantial), while getting more and more sparsed til the end.
Thanks!Ran Kaganhttps://it.mathworks.com/matlabcentral/profile/authors/20965745tag:it.mathworks.com,2005:Question/7269432021-01-26T00:46:09Z2021-01-26T15:06:59ZCropping with image alignmentHi,
I am aligning a set of multiple photos using MATLAB's imregister(). In my set of images, the object grows in size (in the first image, the object is small, and as you go on through the images, the object becomes larger).
When aligning the images, some of the images are getting cropped. AKA the images are technically aligning properly, but when I display the image I see that the object of interest is cut off, not showing the entire object. It appears as though the image was translated downward and the image was cropped according to some kind of boundary.
Can I please have an answer as to why this is happening, and how I could potentially solve the cropping issue? I do not wish to share my code on the forum, just a general answer would be extremely helpful.
Attached is an example drawing to show what is happening.Ashlyn Kapinskihttps://it.mathworks.com/matlabcentral/profile/authors/15388318tag:it.mathworks.com,2005:Question/7273832021-01-26T13:10:11Z2021-01-26T15:05:47ZWhen will sbmlimport support sbml level 3?Would be useful to know. I believe 2020b only supports level 2, correct?
Has anyone else run into having to use an sblm level 3 model? How do you handle this?
Thanks.Jim Bosleyhttps://it.mathworks.com/matlabcentral/profile/authors/8419909tag:it.mathworks.com,2005:Question/7249772021-01-23T14:36:09Z2021-01-26T15:04:41ZHow to perform a zoom FFT on certain portion of a signalI have a signal with a sample rate of 200HZ, see attached. I am interested in a certain portion of the signal, so I zoomed in that section from the original signal (see figure below). I want to compute FFT (maybe zoom FFT) on that portion to see the frequencies within that region. Please I need help, thank you.
Austin Ukpeborhttps://it.mathworks.com/matlabcentral/profile/authors/15290507tag:it.mathworks.com,2005:Question/7268132021-01-25T20:05:11Z2021-01-26T15:03:46Zdragging a selected point within uiaxesHello,
wihin standard figure and axes, I can easely move point.
These points are the graphical representation of complex numbers, so when I move a point I must move its conjugate accordingly.
All works fine with classical figure. I currently use gco to obtain the current point handle. What would be the equivalent with uiaxes within an uifigure?
Best RegardsAlain Barraudhttps://it.mathworks.com/matlabcentral/profile/authors/2029305tag:it.mathworks.com,2005:Question/7261832021-01-25T08:00:19Z2021-01-26T15:00:39ZConvenient handling of datetime function arguments and class propertiesHi folks,
At work, we're in the process of adopting Matlab's new datetime type. We're on R2019b currently. Our code previously used primarily datenums and datestr cellstrs or charvecs to represent dates. And we're running in to a couple hitches.
My first thought was to take class properties and function arguments that used to take datenums or datestrs as inputs, and slap a datetime validator on them:
classdef Foo
properties
aDate datetime
end
methods
function fcn(this, dt)
arguments
this
dt datetime
end
end
end
end
But that didn't work out, because Matlab's one-arg datetime(x) constructor interprets numeric inputs as datevecs, not datetimes. This surprised me, because I thought datetimes were more common than datevecs, and there's a more natural correspondence between datenum and datetime than datevec and datetime, because in a datenum array, each element represents a single date value, the same as in a datetime array.
The other hitch we're running in to is that the datetime(str) constructor that takes string inputs hits a try/catch in the ordinary "happy path" course of parsing dates. So if your code commonly uses datetime() to convert strings to dates, dbstop if all error becomes basically unusable in your programs.
>> dbstop if all error
>> datetime('1/1/2020')
Caught-error breakpoint was hit in @datetime/private/guessFormat>tryOneFmt at line 154. The error was:
Error using matlab.internal.datetime.createFromString
Unable to convert the text to datetime using the format 'dd-MMM-uuuu'.
154 t = createFromString(tryStr,fmt,2,tz,locale,pivot); % error, don't return NaT
K>> dbquit
>> datetime('1/1/2020 01:23:45')
Caught-error breakpoint was hit in @datetime/private/guessFormat>tryOneFmt at line 154. The error was:
Error using matlab.internal.datetime.createFromString
Unable to convert the text to datetime using the format 'dd-MMM-uuuu HH:mm:ss'.
154 t = createFromString(tryStr,fmt,2,tz,locale,pivot); % error, don't return NaT
K>> dbstack
> In guessFormat/tryOneFmt (line 154)
In guessFormat (line 43)
In datetime (line 632)
K>> version
ans =
'9.7.0.1319299 (R2019b) Update 5'
K>>
I ended up writing my own todatetime() function to use as a substitue for the datetime() constructor, and use that instead of argument validators. todatetime in MatlabProjectTemplate
classdef foo
properties
aDate datetime
end
methods
function fcn(this, dt)
dt = todatetime(dt);
end
function this = set.aDate(this, aDate)
this.aDate = todatetime(aDate);
end
end
end
How are you all handling function signatures and class property constraints in codebases that have a mix of datetimes and datenums? What are you doing about that try/catch issue?
In your code, prior to datetime, were your date values predominantly datenums or datevecs?Andrew Jankehttps://it.mathworks.com/matlabcentral/profile/authors/9872961tag:it.mathworks.com,2005:Question/7192352021-01-17T13:24:31Z2021-01-26T15:00:03ZMask-RCNN training in MATLAB for Instance Segmentation Example ErrorI am trying to run the example file (MaskRCNNTrainingExample.mlx) and I have some errors after two iterations. Please help me to fix the errors below. Thank you.
|=========================================================================|
| Epoch | Iteration | Time Elapsed | Mini-batch | Base Learning |
| | | (hh:mm:ss) | Loss | Rate |
|=========================================================================|
| 1 | 1 | 00:01:51 | 3.2167 | 0.0100 |
| 1 | 2 | 00:04:00 | 1.4978 | 0.0100 |
Error using nnet.internal.cnn.dlnetwork/forward (line 254)
Layer 'bn2a_branch2a': Invalid input data. The value of 'Variance' is invalid. Expected input to be positive.
Error in nnet.internal.cnn.dlnetwork/CodegenOptimizationStrategy/propagateWithFallback (line 103)
[varargout{1:nargout}] = fcn(net, X, layerIndices, layerOutputIndices);
Error in nnet.internal.cnn.dlnetwork/CodegenOptimizationStrategy/forward (line 52)
[varargout{1:nargout}] = propagateWithFallback(strategy, functionSlot, @forward, net, X, layerIndices, layerOutputIndices);
Error in dlnetwork/forward (line 347)
[varargout{1:nargout}] = net.EvaluationStrategy.forward(net.PrivateNetwork, x, layerIndices, layerOutputIndices);
Error in networkGradients (line 21)
[YRPNRegDeltas, proposal, YRCNNClass, YRCNNReg, YRPNClass, YMask, state] = forward(...
Error in deep.internal.dlfeval (line 18)
[varargout{1:nout}] = fun(x{:});
Error in dlfeval (line 41)
[varargout{1:nout}] = deep.internal.dlfeval(fun,varargin{:});cheng mao honghttps://it.mathworks.com/matlabcentral/profile/authors/18070784tag:it.mathworks.com,2005:Question/7274832021-01-26T15:00:03Z2021-01-26T15:00:03ZKinetics model-Why i dont get 3 graphs of these modeling, but i get just one for C catalyst. Is there problem with definition of k? function Pd
t_span=[0 1000];
c0=[1 1 1 0 0 0 0 0 0];
[t,c]=ode45(@kinetics,t_span,c0);
plot(t,c)
xlabel('Time,[min]');
ylabel('Concentration,[mol/cm^3]');
legend('cct-CDT','ctt-CDT','ttt-CDT','cc-CDD', 'ct-CDD', 'tt-CDD', 'c-CDE', 't-CDE', 'CDA')
end
function dz=kinetics(t,c);
k=[0.105 0.097 0.065 0.071 0.060 0.056 0.065 0.250 0.061 0.07 0.0110 0.120; %%C
0.015 0.007 0.010 0.008 0.025 0.016 0.005 0.003 0.007 0.015 0.001 0.035; %%CaCO3
0.090 0.078 0.070 0.058 0.125 0.045 0.069 0.007 0.073 0.080 0.006 0.039]; %%Al2O3
dz=zeros(9,3);
r1=k(1)*c(1);
r2=k(2)*c(1);
r3=k(3)*c(2);
r4=k(4)*c(2);
r5=k(5)*c(3);
r6=k(1)*c(1)-k(6)*c(4);
r7=k(2)*c(1)+k(3)*c(2)-k(7)*c(5)-k(8)*c(5)-k(9)*c(5);
r8=k(4)*c(2)+k(5)*c(3)-k(10)*c(6);
r9=k(6)*c(4)+k(7)*c(5)-k(11)*c(7);
r10=k(9)*c(5)+k(10)*c(6)-k(12)*c(8);
r11=k(11)*c(7)+k(8)*c(5)+k(12)*c(8);
dz(1)=-r1-r2;
dz(2)=-r3-r4;
dz(3)=-r5;
dz(4)=r6;
dz(5)=r7;
dz(6)=r8;
dz(7)=r9;
dz(8)=r10;
dz(9)=r11;
endSvetlana Trundováhttps://it.mathworks.com/matlabcentral/profile/authors/19576729tag:it.mathworks.com,2005:Question/7268982021-01-25T22:49:51Z2021-01-26T14:56:48ZQuestion about accessing data in a structHi all,
I am trying to get data from an xml file using xml2struct. currently, I am calling on the data using the syntax
DataSet.Children(x).Children(y).Children(z).Children.Data
where Dataset is my structure and x, y and z are integers referring to the index position. The problem is that sometimes the xml structure stores the same information in different positions meaning x, y and z will be different for these. For example, the "date" field might be the 3rd index (x=3) in one file, or the 2nd index (x=2) in another.
Is there a way to navigate around this please? I need to have a consistent way to gather this data because I loop through several xml files, so I need to get the same, consistent information from all the files with certainty.
I have tried to use "find" but to no avail.
Thank you in advance
The code:
Accessing the data
close all
clear all
clc
Asking the user to select the folder with the Images and Auto analysis in
startingFolder = pwd;
fprintf('Select the directory containing the Images and Auto analysis \n \n');
RawImages = uigetdir(startingFolder); %Creating the variable from the user selection
addpath(RawImages); %Ensuring matlab will follow the path
files = dir([RawImages '\AutoAnalysis\*.xml']);
numOfFiles = numel(files); %Counting number of files in the folder for looping purposes
Settings = xml2struct([RawImages '\settings.xml']); %Converting XML to structure then accessing the number of the samples from the Settings file
NumOfSamples = str2double(Settings.Children(20).Children.Data);
headings = {'Time','Temperature','Height','Area','Circumference', 'Shape Factor', 'Tip Radius', 'Base Width', 'Max Width', 'Height:Base Width Ratio', 'Height:Max Width Ratio', 'Bse Centre X', 'Base Centre Y', 'LHS Difference', 'RHS Difference'};
objectRangeEnd = strcat('O', num2str(numOfFiles));
objectRange = strcat('A2:', objectRangeEnd);
for j = 1:NumOfSamples %Getting the manually named test pieces from the settings
TestPieceName = Settings.Children(22).Children((2*j)).Children(4).Children.Data; %Creating a name variable to use when making file and folder names
Sample = ['Test Piece ' num2str(j) '-' TestPieceName];
TestPiece = zeros(numOfFiles,3); %Making an array to store the variables
for k = 1:numOfFiles %Grabbing the time and file data from the save file name
flds = {'date','bytes','isdir','datenum'}; %Reading time and temp from file
A = rmfield(files,flds); %Remove the file information that is unnecessary
codes = struct2cell(A); %Reduces the structure to only the fields required
codes = codes'; %Converts the labels in A to the format required
new = strsplit(char(codes(k)),'.'); % To remove the file type
new2 = strsplit(char(new(1)),'-'); % Splits the experimental conditions
time = str2double(new2(2));
alpha = new2(3);
alpha = char(alpha);
alpha(1) = [];
temp = str2double(alpha);
TestPiece(k,1) = time;
TestPiece(k,2) = temp;
file = [ RawImages '\AutoAnalysis\' files(k).name]; % Creating the k-th file name
DataSet = xml2struct(file); % Converting XML files to structures
datasetNum= numel(DataSet.Children);
testPieceLocation = datasetNum - NumOfSamples + j; %Indexing Height, Area, and Circumference etc.
TestPiece(k,3) = str2double(DataSet.Children(testPieceLocation).Children(end).Children('height').Children.Data); %Height
TestPiece(k,4) = str2double(DataSet.Children(testPieceLocation).Children(end).Children().Children.Data); %Area
TestPiece(k,5) = str2double(DataSet.Children(testPieceLocation).Children(end).Children(find('circumference')).Children.Data); %Circumference
TestPiece(k,6) = str2double(DataSet.Children(testPieceLocation).Children(end).Children(find('shapeFactor')).Children.Data); %Shape Factor
TestPiece(k,7) = str2double(DataSet.Children(testPieceLocation).Children(end).Children(find('tipRadius')).Children.Data); %Tip Radius
TestPiece(k,8) = str2double(DataSet.Children(testPieceLocation).Children(end).Children(5).Children.Data); %Base width
TestPiece(k,9) = str2double(DataSet.Children(testPieceLocation).Children(end).Children(6).Children.Data); %Max Width
TestPiece(k,10) = str2double(DataSet.Children(testPieceLocation).Children(end).Children(find('hBwRatio')).Children.Data); %hBw Ratio
TestPiece(k,11) = str2double(DataSet.Children(testPieceLocation).Children(end).Children(find('hMwRatio')).Children.Data); %hMw Ratio
TestPiece(k,12) = str2double(DataSet.Children(testPieceLocation).Children(end).Children(1).Children.Data); %Base Centre X
TestPiece(k,13) = str2double(DataSet.Children(testPieceLocation).Children(end).Children(2).Children.Data); %Base Centre Y
TestPiece(k,14) = str2double(DataSet.Children(testPieceLocation).Children(end).Children(3).Children.Data); %LHS Diff
TestPiece(k,15) = str2double(DataSet.Children(testPieceLocation).Children(end).Children(4).Children.Data); %RHS Diff
initialheight = TestPiece(1,3);
initialarea = TestPiece(1,4);
initialcirc = TestPiece(1,5);
initialSFactor = TestPiece(1,6);
initialTRad = TestPiece(1,7);
initialBW = TestPiece(1,8);
initialMWidth = TestPiece(1,9);
initialHBW = TestPiece(1,10);
initialHMW = TestPiece(1,11);
initialBaseCX = TestPiece(1,12);
initialBaseCY = TestPiece(1,13);
initialLHSDiff = TestPiece(1,14);
initialRHSDiff = TestPiece(1,15);
TestPiece(k,3) = TestPiece(k,3)/initialheight;
TestPiece(k,4) = TestPiece(k,4)/initialarea;
TestPiece(k,5) = TestPiece(k,5)/initialcirc;
TestPiece(k,6) = TestPiece(k,6)/initialSFactor;
TestPiece(k,7) = TestPiece(k,7)/initialTRad;
TestPiece(k,8) = TestPiece(k,8)/initialBW;
TestPiece(k,9) = TestPiece(k,9)/initialMWidth;
TestPiece(k,10) = TestPiece(k,10)/initialHBW;
TestPiece(k,11) = TestPiece(k,11)/initialHMW;
TestPiece(k,12) = TestPiece(k,12)/initialBaseCX;
TestPiece(k,13) = TestPiece(k,13)/initialBaseCY;
TestPiece(k,14) = TestPiece(k,14)/initialLHSDiff;
TestPiece(k,15) = TestPiece(k,15)/initialRHSDiff;
end
sampleDirectory = fullfile(RawImages); %file creation
filename = fullfile(sampleDirectory, ['Results.xls']); %Creating the filename to put the excel file in the appropriate folder
writecell(headings, filename, 'Sheet', Sample, 'Range', 'A1:O1');
writematrix(TestPiece, filename, 'Sheet', Sample, 'Range', objectRange);
endTeshan Rezelhttps://it.mathworks.com/matlabcentral/profile/authors/17128181tag:it.mathworks.com,2005:Question/7273582021-01-26T12:34:28Z2021-01-26T14:53:33ZData type of matlab files Hello,
I have a question concerning the data types of my matlab files. I accidently changed the format of the files to PDF´s, instead of .m data. This leads to the problem that I cannot make matlab read in images and other data. Does somebody know how I can change the data type back to .m data? Bätcher Katrinahttps://it.mathworks.com/matlabcentral/profile/authors/12581888tag:it.mathworks.com,2005:Question/7269682021-01-26T01:57:40Z2021-01-26T14:53:28ZExtract subsets of consecutive entries in a matrixI have an n x p matrix, A, of multivariate data. (n - data points, p - independent variables).
I want to select random subsets (i.e. extract collections of rows) from this data of size (p+1). The subsets need to be comprised of rows that are consecutive.
For example:
matrix = rand(100,4);
%n = 100, n data points
%p = 4, p independent variables
I want to create a random subset of 5 rows (p+1 = 5). So, rows 1 through 5 or 43 through 47, etc.
I know there are functions like randsample and datasample but I'm not sure how to use these to get subsets of rows that are together and not chosen at random throughout the matrix.Zavian Buchananhttps://it.mathworks.com/matlabcentral/profile/authors/11608008tag:it.mathworks.com,2005:Question/7274782021-01-26T14:50:34Z2021-01-26T14:50:34ZSurface Roughness Metrology Tool according to ISO 25178Hi everyone,
I am looking for a Matlab Tool/Function that provides surface roughness values (Sa,Sz,W), out of an input vector that contains information about the real structure of the measured component. The Tool must be according to ISO 25178 or rather filtration must be according to ISO 16610-21.
Note: Output values should not be Ra,Rz values but rather Sa,Sz values.
I have found the following surface metrology tool:
https://de.mathworks.com/matlabcentral/fileexchange/52892-surface-metrology-open-profile-gaussian-filter?s_tid=srchtitle
Basically the tool uses gaussians filters to determine waviness and roughness out of the primary structure (see attached Figure). So this is part of the solution I am looking for. What remains is the ISO filtration of the real values to the primary values.
Is there any Matlab tool that does that or even better a tool which combines both filter viz. performs the whole filtration pictured in the attached figure?
Thanks in advance!Brendan Görreshttps://it.mathworks.com/matlabcentral/profile/authors/13254816tag:it.mathworks.com,2005:Question/7274732021-01-26T14:47:44Z2021-01-26T14:47:44ZI used window visualization tool, can anyone explain what is going amplitude, sample, magnitude and normalized frequency? I am cluelessmuhammad nur adri nawihttps://it.mathworks.com/matlabcentral/profile/authors/14390011tag:it.mathworks.com,2005:Question/6536732020-11-19T15:51:13Z2021-01-26T14:43:04ZCreate organized pointcloud from normal pointcloudHey,
For a project I needed to edit the data that came from the Simulation 3D Lidar block in Simulink, however the pointcloud that comes from this block is an organized pointcloud and it is read only. So I created an nomal pointcloud with the XYZ location data from each measurement. However now I need to use the segmentGroundFromLidarData function to remove the ground plane. And this function is only able to work with an organized pointcloud.
So that is where my problem is, I need to find a way to either edit the data while it is still in the organized pointcloud or transform an unorganized pointcloud back into an organized pointcloud. Does anybody know how I can do this?
ThanksBram Surewaardhttps://it.mathworks.com/matlabcentral/profile/authors/5688033tag:it.mathworks.com,2005:Question/7274682021-01-26T14:42:28Z2021-01-26T14:42:28ZCan I make money with the Trading Toolbox?Are Matlab Home users allowed to benefit financially from algorithmic trading? It seems like the the purpose of the trading toolbox.Tristan Cajahttps://it.mathworks.com/matlabcentral/profile/authors/18519861tag:it.mathworks.com,2005:Question/7267532021-01-25T18:14:16Z2021-01-26T14:41:53ZIs there a way to swap axes on spectrogram?Hi!
Is there a way to swap x and y axis in lower subplot - spectrogram? Script for spectrogram is generated from Signal Analyzer app.
I need frequency on horizontal axis and time on vertical axis.
timeLimits = [0 3.981311]; %[s]
frequencyLimits = [0 120000]; %[Hz]
overlapPercent = 50;
svetlobni_tok_ROI = svetlobni_tok(:);
sampleRate = 1000000; %[Hz]
startTime = 0; %[s]
figure(2)
%FFT
minIdx = ceil(max((timeLimits(1)-startTime)*sampleRate,0))+1;
maxIdx = floor(min((timeLimits(2)-startTime)*sampleRate,length(svetlobni_tok_ROI)-1))+1;
svetlobni_tok_ROI = svetlobni_tok_ROI(minIdx:maxIdx);
subplot(2,1,1)
pspectrum(svetlobni_tok_ROI,sampleRate,'FrequencyLimits',frequencyLimits);
%Spectrogram
timeValues = startTime + (0:length(svetlobni_tok_ROI)-1).'/sampleRate;
minIdx = timeValues >= timeLimits(1);
maxIdx = timeValues <= timeLimits(2);
svetlobni_tok_ROI = svetlobni_tok_ROI(minIdx&maxIdx);
timeValues = timeValues(minIdx&maxIdx);
subplot(2,1,2)
pspectrum(svetlobni_tok_ROI,timeValues,'spectrogram','FrequencyLimits',...
frequencyLimits,'OverlapPercent',overlapPercent);Matic Markovichttps://it.mathworks.com/matlabcentral/profile/authors/18237768tag:it.mathworks.com,2005:Question/7225332021-01-20T22:02:12Z2021-01-26T14:40:13Zproblem in the for - loopHere is the problem
Ive got a FEM code
function main1
clc
n = 100;
x0 = ones(3*n,1);
sol = fsolve(@(x)fun(x,n),x0);
norm(fun(sol,n))
x = ((1:n)-1)/(n-1);
plot(x,sol(1:n))
end
function res = fun(z,n)
eta=1.0;
beta = 1.0;
x = ((1:n)-1)/(n-1);
dx = 1/(n-1);
y1 = z(1:n);
y2 = z(n+1:2*n);
y3 = z(2*n+1:3*n);
for i=1:length(y1)
Y1=y1(i);
end
for i=1:length(y2)
Y2=y2(i);
end
res_y1 = zeros(n,1);
res_y2 = zeros(n,1);
res_y3 = zeros(n,1);
res_y1(1) = y1(1)-10.0;
for i=2:n-1
res_y1(i) = (y1(i+1)-2*y1(i)+y1(i-1))/dx^2 + (y1(i+1)-y1(i-1))/(2*dx) + exp(-5/Y2);
end
res_y1(n) = y1(n);
res_y2(1) = y2(1);
for i = 2:n-1
res_y2(i) = (y2(i+1)-2*y2(i)+y2(i-1))/dx^2 - y1(i).^2;
end
res_y2(n) = y2(n)-eta;
res_y3(1) = y3(1);
for i=2:n-1
res_y3(i) = (y3(i+1)-2*y3(i)+y3(i-1))/dx^2 - Y2;
end
res_y3(n) = y3(n)-1.0;
res = [res_y1;res_y2;res_y3];
end
It seems that using
res_y1(i) = (y1(i+1)-2*y1(i)+y1(i-1))/dx^2 + (y1(i+1)-y1(i-1))/(2*dx) + exp(-5/Y2);
and
res_y1(i) = (y1(i+1)-2*y1(i)+y1(i-1))/dx^2 + (y1(i+1)-y1(i-1))/(2*dx) + exp(-5/y2(i));
must be eqiuvalent, but NO. The results differGlebhttps://it.mathworks.com/matlabcentral/profile/authors/4740376tag:it.mathworks.com,2005:Question/7247182021-01-23T06:37:12Z2021-01-26T14:37:32ZHow to fix this one? I use PI controller. please give a suggestion on this matter?Nyam Jargalsaikhanhttps://it.mathworks.com/matlabcentral/profile/authors/18514807tag:it.mathworks.com,2005:Question/7274632021-01-26T14:37:27Z2021-01-26T14:37:27ZHow to calculate Picture length from picture? I have to calculated it in micron? can you guys tell me an code ?How to calculate Picture length from picture? I have to calculated it in micron? can you guys tell me an matlab code ?Devesh Singhhttps://it.mathworks.com/matlabcentral/profile/authors/21268462tag:it.mathworks.com,2005:Question/7270482021-01-26T05:18:31Z2021-01-26T14:34:19ZOptimization issue, always different results?Hello everyone,
I'm trying to optimize a set of 3 parameters by using the following function:
options=optimset('Algorithm','levenberg-Marquardt', 'LargeScale','off', 'DiffMaxChange',0.01, 'DiffMinChange',0.0001, 'TolFun',1e-5, 'TolX',0.001);
[x,resnorm,residual,exitflag,output,lambda,jacobian]=lsqnonlin(@HSfun,x0,lb,ub,options);
At the end of the script, the function is reduced to a subtraction of vectors, so I do not consider important to post the whole script here. Input data is brought to the script from excel, and that's it. 3 parameters are optimized until reaching one of the optimization stopping criteria.
Altought I utilize Trust Reflective Region (default optimization Algorithm) instead of levenberg-Marquardt, the results of the optimization are always different for the same input data. And the results are sometimes more accurate than others.
My question is: Is this normal? These functions give you always different parameters answers even if the input data to optimize is the same?
Thanks in advance!Daniel Valenciahttps://it.mathworks.com/matlabcentral/profile/authors/19385420tag:it.mathworks.com,2005:Question/7274432021-01-26T14:06:19Z2021-01-26T14:31:54Zplotting graph using table dataI want to plot a graph T2 (y-axis) against time(x-axis). what code should I use?kevin Leehttps://it.mathworks.com/matlabcentral/profile/authors/21243697tag:it.mathworks.com,2005:Question/7242282021-01-22T15:23:25Z2021-01-26T14:30:45ZTo Expand Subsystem by using model explorerHi,
is it possible any subsystem to expand by using model exploerer?
Thank you in advance
MustafaMustafa Usluhttps://it.mathworks.com/matlabcentral/profile/authors/16041761tag:it.mathworks.com,2005:Question/7274482021-01-26T14:11:24Z2021-01-26T14:28:27ZHow to make a for loop add results together consecutively?Hi, very new to Matlab and coding in general, I can't work out how to use a for loop to calculate individual results and add them together one by one as it progresses. I have a set of readings for acceleration at a fixed range of velocities, and my script can calculate the time taken to accelerate from each velocity reading to the next, but I cannot work out how to have my for loop add each time reading as it is calculated in order to plot time against velocity.
Airspeed.Thrust is a set of thrust readings from a separate table.
l = 2.4 %wingspan
m = 0.465+(l*0.1) %mass of aircraft
%calc
a = Airspeed.Thrust./m
%loop
t = 0
for v = 0:16
t = (1./a)
end
I tried to alter my loop to:
for v = 0:16
t = t+(1./a)
end
But for some reason this gives a completely different starting value, but produces an identically shaped graph.Dexter Greenehttps://it.mathworks.com/matlabcentral/profile/authors/20002200tag:it.mathworks.com,2005:Question/7214742021-01-19T19:20:24Z2021-01-26T14:22:18Zmatlab 2021-a Good evening my friends, when will the Matlab 2021-a version be available on the site ?
omar khasawnehhttps://it.mathworks.com/matlabcentral/profile/authors/18293057tag:it.mathworks.com,2005:Question/970742010-01-22T16:45:00Z2021-01-26T14:20:50ZHow do I solve an ODE with time-dependent parameters in MATLAB?Consider the following ODE with time-dependent parameters:
y'(t) + f(t)y(t) = g(t)
and the given initial condition:
y(0) = 1
This is an example of an ODE with time-dependent terms. Suppose the time-dependent terms are defined only through the set of data points given in two vectors. Which of the MATLAB ODE solvers should I use, and how do I set up this problem?MathWorks Support Teamhttps://it.mathworks.com/matlabcentral/profile/authors/4622813tag:it.mathworks.com,2005:Question/7274582021-01-26T14:17:51Z2021-01-26T14:17:51Zmatlab and simulation full course Good evening , I am looking for a course that explains topics related to this book in matlab ?
https://drive.google.com/file/d/1tcqMXjXaCOzM-6NAENGv4gqph3U-bJ6M/view?fbclid=IwAR1BmyTPLAC-oqqkZUSVxUYeELcaZqAxCCqPV3QCF21ekuV0x6X5iT2eUpYomar khasawnehhttps://it.mathworks.com/matlabcentral/profile/authors/18293057tag:it.mathworks.com,2005:Question/994572012-07-30T22:20:00Z2021-01-26T14:13:42ZHow do I activate MATLAB or other MathWorks Products?How do I activate MATLAB?MathWorks Support Teamhttps://it.mathworks.com/matlabcentral/profile/authors/4622813tag:it.mathworks.com,2005:Question/7274532021-01-26T14:11:58Z2021-01-26T14:11:58ZIs it possible to fit multiple data sets in the same 'fit'??So my dilema is that the code below runs the first fit until 'DiffMinChange' is satisfied and then it moves to the second fit. I want to know if it is possible to operate both fits and then check 'DiffMinChange'. I assume I will need a while statement, but I am not sure how the 'fit' function will react. Any help is appreciated!
% Define first fittype
ft1 = fittype('FitLT1(xdata1, mtrlmod, cgs, cds, cgd0, coxd, vtd, vtdtco, fc, m, wb, nb, a, agd, thetal, thetalr, thetah, thetaltexp, thetahtexp, kfl, kfh, kpl, kph, kflr, kplr, kfltexp, kfhtexp, kpltexp, kphtexp, vtl, vth, vtlr, vtltco, vthtco, vbigd, pvfl, pvfh, slmin, id0, vb, rs, rd, rdr, rdvd, rdvg11, rdvg12, rdtemp1, rdtemp2, rdvdtemp1, rdvdtemp2, rdiode, is_body, kvsg1, kvsg2, nd, temperature, tnom, vk1, vk2, tt, tau, multiplier, p_delta, thetalrtexp, kplrtexp, rdrtemp1, rdrtemp2, rdiodetemp1, rdiodetemp2, vtlrtco, vk1tco, vk2tco, ndtco, kvsg1texp, kvsg2texp)',...
'independent', {'xdata1'},...
'dependent', {'ydata1'},...
'problem', optInfo1.const_vars,...
'coefficients', optInfo1.opt_params);
% Call first fitting function and save the optimized parameter values,
% measurements on goodness of fit, and optimization data.
[fit_result1, gof1, fit_info1] = fit(xdata1, ydata1, ft1, 'problem', optInfo1.const_vals,...
'Lower', optInfo1.lower_bound, 'Upper', optInfo1.upper_bound, 'DiffMinChange', optInfo1.min_diff);
% Define second fittype
ft2 = fittype('FitLT2(xdata2, mtrlmod, cgs, cds, cgd0, coxd, vtd, vtdtco, fc, m, wb, nb, a, agd, thetal, thetalr, thetah, thetaltexp, thetahtexp, kfl, kfh, kpl, kph, kflr, kplr, kfltexp, kfhtexp, kpltexp, kphtexp, vtl, vth, vtlr, vtltco, vthtco, vbigd, pvfl, pvfh, slmin, id0, vb, rs, rd, rdr, rdvd, rdvg11, rdvg12, rdtemp1, rdtemp2, rdvdtemp1, rdvdtemp2, rdiode, is_body, kvsg1, kvsg2, nd, temperature, tnom, vk1, vk2, tt, tau, multiplier, p_delta, thetalrtexp, kplrtexp, rdrtemp1, rdrtemp2, rdiodetemp1, rdiodetemp2, vtlrtco, vk1tco, vk2tco, ndtco, kvsg1texp, kvsg2texp)',...
'independent', {'xdata2'},...
'dependent', {'ydata2'},...
'problem', optInfo2.const_vars,...
'coefficients', optInfo2.opt_params);
% Call second fitting function and save the optimized parameter values,
% measurements on goodness of fit, and optimization data.
[fit_result2, gof2, fit_info2] = fit(xdata2, ydata2, ft2, 'problem', optInfo2.const_vals,...
'Lower', optInfo2.lower_bound, 'Upper', optInfo2.upper_bound, 'DiffMinChange', optInfo2.min_diff);
Steven Manzhttps://it.mathworks.com/matlabcentral/profile/authors/11620537tag:it.mathworks.com,2005:Question/7273982021-01-26T13:32:48Z2021-01-26T14:11:31ZRunning the code takes too long to finish(Euler's Method)I'm trying to create a code to use Euler's method in solving the differential equation as shown below. When I try to run the code, it takes a long time to do each iteration. I feel I have made a mistake when declaring variables. I have also placed a picture of a segment of the supposed output of the code which I got from my professor. Any insight would be appreciated.
rho=1000;
g=9.8;
A_tank=3.13;
A_pipe=0.06;
C=pi/12;
K1=300;
K2=1000;
syms dh(t,h)
dh(t,h)=(K1+K2*sin(5*C*t)*cos(C*t)-rho*A_pipe*(2*g*h)^(1/2))/(rho*A_tank);
t=0;
tn=150;
h=3;
s=0.1;
ts=t:s:tn;
hwt=[];
fprintf('time \t\t height \n')
fprintf('%f \t %f\t \n',t,h)
for i=1:numel(ts)
h=h+dh(t,h)*s;
t=t+s;
fprintf('%f \t %f\t \n',t,h);
hwt(i)=h;
end
plot(ts,hwt)
Marco Serranohttps://it.mathworks.com/matlabcentral/profile/authors/19545708tag:it.mathworks.com,2005:Question/7171382021-01-14T16:42:19Z2021-01-26T14:11:29ZHow can I get a calculated function value??? I want to calculate Lagrangian fuction.
L(x_wt11, x_wt21, x_wt12, x_wt22) = Vt1 * ( (1-p_wt11)^x_wt11 * (1-p_wt21)^x_wt21 )...
+ Vt2 * ( (1-p_wt12)^x_wt12 * (1-p_wt22)^x_wt22 )...
- lambda1 * ( 1-(x_wt11 + x_wt12))...
- lambda2 * ( 1-(x_wt21 + x_wt22))...
- lambda3 * ( Vw1 * (1-s_wt11/u)^x_wt11 * (1-s_wt12/v)^x_wt12...
+ Vw2 * (1-s_wt21/u)^x_wt21 * (1-s_wt22/v)^x_wt22 - 2 * beta);
When I input L(0,0,0,0) (or L(1,0,0,0), L(0,1,1,0)...etc)
the answer is not calculated value, although I declare all parameters.
In this equation, "x_wt11, x_wt21, x_wt12, x_wt22" are binary variable,
and anothers are parameters(constant).
I declare parameters before this equation except 'u, v'
because 'u,v' are dependent on "x_wt11, x_wt21, x_wt12, x_wt22" value.
In summary,
1. declare parameters. (except 'u,v')
2. declare Lagrangian function.
3. declare parameters 'u, v'
* The reason why I declaring 'u,v' afterwards, I want to prevent deviding by zero.
* u = x_wt11 + x_wt21 , v = x_wt12 + x_wt22
* So, if "x_wt11=0", "x_wt21=0", and then u is zero.
* To solve this problem, I use "if" statement.
if (x_wt11+x_wt21) == 0
u=1;
elseif (x_wt11+x_wt21) == 1
u=1;
elseif (x_wt11+x_wt21) == 2
u=2;
else
u=0;
end
And then, if I input "L(0,0,0,0)"
the answer is like this way, "52/(22*u) + 69/(22*v) + 74/56"
I declare parameters 'u,v' but, Why the answer is not a calculated??? and How I can solve this problem???
연승 김https://it.mathworks.com/matlabcentral/profile/authors/20512103tag:it.mathworks.com,2005:Question/7273332021-01-26T12:28:49Z2021-01-26T14:08:41ZHow to change the font of a pie chart?I want to change the font of pie chart in this code. However, I could not change. Thank you!
width = 6; % Width in inches
height = 3; % Height in inches
alw = 0.75; % AxesLineWidth
fsz = 14; % Fontsize
lw = 1.5; % LineWidth
msz = 8; % MarkerSize
legl1=5; % legen length size
legl2=5; % legen length size
LOC='northwest'; % location of legend
%fig = figure; clf
close all
%% Vs=340 Rl=200
figure (1)
subplot(1,2,1)
hold on
X1 = categorical({'S_1','S_2','L_p','L_r','C_{link}','D'});
X1 = reordercats(X1,{'S_1','S_2','L_p','L_r','C_{link}','D'});
X= [0.16 0.093 0.25 ; 0.06 0.125 0.185; 0 2.44 2.44 ; 0 1.8 1.8 ; 0 3.5 3.5 ; 0 1.6 1.6 ];
bar(X1,X);
%title('Second Subplot','fontName','Times')
ylabel('Power losses (W)','fontName','times','FontSize',20);
%xlabel('f_s/f_0','fontName','Time new Roman','FontSize',20);
pos = get(gcf, 'Position');
leg=legend('Switching Loss' ,'Conduction Loss','Total Loss','boxoff','Location',LOC);
leg.ItemTokenSize = [legl1,legl2];
set(gcf, 'Position', [pos(1) pos(2) width*100, height*100]); %<- Set size
set(gca, 'FontSize', fsz, 'LineWidth', alw,'fontname','times'); %<- Set propertieslegend('Conduction Loss','Switching Loss','Total Loss','fontName','Time new Roman');
ylim([0 4])
hold off
b2=subplot(2,2,2);
X1= [(2.1*100/7.3) (3.5*100/7.3) (3*100/7.3) ];
explode = {'Inverter(28%)','Resonant tank(48%)','Rectifier (24%)'};
pie(X1,explode);
hold on
set(gcf, 'Position', [pos(1) pos(2) width*100, height*100]); %<- Set size
set(gca,'fontName','times', 'FontSize', fsz, 'LineWidth', alw); %<- Set properties
dx0 = -0.06;
dy0 = -0.4;
dwithx = 0.1;
dwithy = 0.23;
set(b2,'position',get(b2,'position')+[dx0,dy0,dwithx,dwithy],'fontName','times')
set(gca,'LooseInset', max(get(gca,'TightInset'), 0.08),'fontName','times')
hold off
Tin Truong Chanhhttps://it.mathworks.com/matlabcentral/profile/authors/13044143tag:it.mathworks.com,2005:Question/7210842021-01-19T12:06:54Z2021-01-26T14:08:38ZHow to formulate elegantly and performant functions that depend on a lot of input variablesHello,
I am not new to MATLAB. However, I have the following problem:
If I have a function e.g.:
output = f(in1,in2,in3,in4,in5,in6,...)
which depends on a lot of input variables.
How can I design it as elegant as possible but at the same time performant?
If I use a strcut e.g.
input.in1
input.in2
input.in3
...
I can formulate the function nice and short:
output = f(input)
But the problem is that the variable naming is fixed for the input as well as in the function. Furthermore, calling values from a struct is slow, so in the function they have to be read first:
function [output] = f(input)
in1 = input.in1
in2 = input.in2
in3 = input.in3
...
% calculations with in1,in2,in3,...
end
I also know that you should not write a function with so many input variables, yet it happens.
How do you handle such cases? Ferdinand Breithttps://it.mathworks.com/matlabcentral/profile/authors/9184835tag:it.mathworks.com,2005:Question/7273782021-01-26T13:08:44Z2021-01-26T14:02:39ZFind rows in MATRIX based on position of elementsConsider I have a binary matrix H
H = [1 1 0 1 1 0 0 1 0 1;
0 0 0 1 0 1 0 0 1 1;
0 1 1 0 1 0 1 0 0 1;
1 1 0 0 0 0 1 0 1 1;
0 0 1 0 0 1 0 1 0 1];
From this Matrix I am supposed to select a part which becomes E matrix
E = H(4:end, 8:end);
E = [0 1 1;
1 0 1];
Now what I need is - I need to find the rows in H which have 1s in positions equal to the positions of 1s in E
How do I achieve this in a simple way. Please help, people...
Edit - Basically the answer I need is row 1 and 2. How do I get it?Rishi Balasubramanianhttps://it.mathworks.com/matlabcentral/profile/authors/14728945tag:it.mathworks.com,2005:Question/7271932021-01-26T09:48:27Z2021-01-26T14:02:17ZHow to solve this problem in MatLabprogram?Hello, I need your help solving this problem: Two beads of mass 2m and m can move without friction along a horizontal wire. They are connected to a fixed wall with two springs of spring constants 2k and k as shown in Fig. 7.6: (a) Find the Lagrangian for this system and derive from it the equations of motion for the beads. (b) Find the eigenfrequencies of small amplitude oscillations. (c) For each normal mode, sketch the system when it is at the maximum displacement.
System kinetic energy
Potential energy
Langrange function of system motion
Langrange motion equations
motion canonic equation
Bacs Gerhard- Danielhttps://it.mathworks.com/matlabcentral/profile/authors/20661168tag:it.mathworks.com,2005:Question/7212992021-01-19T15:47:24Z2021-01-26T13:59:28ZCoulomb 3.3 Build input from CMT or focal mech. dataHello,
I am using Coulomb 3.3. When I try to use the option "Build input from CMT or focal mech. data" I have the next errors:
Unrecognized function or variable 'deg2utm'.
Error in distance2 (line 15)
[x1,y1,utmzone1] = deg2utm(lat1,lon1);
Error in utm_window>pushbutton_calc_Callback (line 273)
[xdist,flag1] = distance2(pcent_lat,MIN_LON,pcent_lat,MAX_LON);
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in utm_window (line 20)
gui_mainfcn(gui_State, varargin{:});
Error using main_menu_window>menu_new_map_Callback (line 167)
Error while evaluating UIControl Callback.
I am using the 3.3.01 version. I downloaded it from USGS.
¿Is it a Coulomb or a Matlab problem? ¿Can someone help me?
Thank you!!!!
Isabel
ISABEL CRISTINA GOMEZ GUTIERREZhttps://it.mathworks.com/matlabcentral/profile/authors/18214450tag:it.mathworks.com,2005:Question/7212142021-01-19T14:16:31Z2021-01-26T13:59:07ZVlaue of Slider --> EditFieldHello everybody,
I´m new to MATLAB and I didnt found out how to get the value of the Slider to the EditField, and the other way around. Can somebody help me?
I am using MATLAB2020b and the App designer, so I don´t have one of these so called "handles" anymore and they are used in every tutorial.
I would be sooo thankful if somebody could help me.
P.S: Sorry for my English, hope you can understand it anyways :)
Kristin Habersanghttps://it.mathworks.com/matlabcentral/profile/authors/20752024tag:it.mathworks.com,2005:Question/7273282021-01-26T12:15:33Z2021-01-26T13:54:55ZHow can I save and plot all values of x and y for each value of V? x and y values are in the vertical axis and V in the horizontal axis in the graphicV=[1,2,3,4];
i=1;
while i<=4
syms x y
eqn1 = V(i)*x + y == 2;
eqn2 = -x + y == 3;
sol = solve([eqn1, eqn2], [x, y]);
xSol = double(sol.x);
ySol = double(sol.y);
endPablo Zarcohttps://it.mathworks.com/matlabcentral/profile/authors/15271389tag:it.mathworks.com,2005:Question/7274332021-01-26T13:52:56Z2021-01-26T13:53:52Zusing a dendrogramm to cluster columns of a matrix with complex entriesHello!
For my research, I am trying to find a suitable method for finding collinear columns in a noisy matrix C. I want to try out different algorithms for this task, and one I would like to test is the dendrogramm function. The dendrogramm function is clustering the rows, therefore I am taking the transpose of the matrix C.' to group the columns, and using the following code:
tree = linkage(C.', 'average', 'correlation')
dendrogramm(tree)
My problem is now, that my matrix is containing complex numbers, and I want to cluster the columns by their inner product. However, MATLAB returns the following error:
Error using internal.stats.linkagemex
Function linkagemex only supports real input.
Error in linkage (line 259)
Z = internal.stats.linkagemex(Y,method,pdistArg, memEff);
Error in dendro(line 14)
tree = linkage(C.', 'average', 'correlation');
Apparently, the linkage function that generates the tree for the dendrogramm is only accepting real data. Do I need to rewrite the linkage function for my purposes, or is there a smoother way to work this out?
Thanks in advance for your help.
EDIT: TypoGabriel Seidlhttps://it.mathworks.com/matlabcentral/profile/authors/18097484tag:it.mathworks.com,2005:Question/7274282021-01-26T13:51:37Z2021-01-26T13:51:37ZJump diffusion simulation problemHello,
I am trying to simulate jump diffusion processes with jump size distrubuted as a variable that can take only two values with probability p,1-p.
I want to leave as a input the number of simulated path but I am still having problem with the code. Do not consider the explanation since I started from another code.
Of course I will delete the input parameter which I set in the screen once it run properly
Can anyone help me?
ThanksEugenio Palmierihttps://it.mathworks.com/matlabcentral/profile/authors/13995417tag:it.mathworks.com,2005:Question/7273382021-01-26T12:30:47Z2021-01-26T13:49:24ZWhy does ishghandle(0) alwys return true?Why does
ishghandle(0)
return true, even if there is no existent graphic object (actually, I executed this line of code first after Matlab startup).Georg Nestlingerhttps://it.mathworks.com/matlabcentral/profile/authors/10192082tag:it.mathworks.com,2005:Question/7274232021-01-26T13:48:12Z2021-01-26T13:48:12ZHow to pass additional variables with serial callback function (R2020b)I am working on continuously displaying data on a gui that comes through a serial port. The data comes in form of one string with a "LF/CR" at the end. The obvious idea is to create a callback function that updates the text field of the gui each time that terminator is detected. The problem is that the callback function need the be in the form of
function mycallback(src, evt)
...
end
but also needs the handles of the gui.
With older Matlab Versions I would just use
configureTerminator(s,"CR/LF")
s.BytesAvailableFcnMode = 'terminator';
s.BytesAvailableFcn = {@mycallback,guiHandles};
function mycallback (src, evt, handles)
...
end
But with the newer versions (I am using 2020b) I am forced to use
configureTerminator(s,"CR/LF")
configureCallback(s,"terminator",@mycallback)
I hoped I could just use
configureCallback(s,"terminator",{@mycallback, guiHandles})
or something like that but that doesnt seem to work as configureCallback requires a @callbackfcn and does not accept arrays or cells. I also couldn't find anything on the internet for this matlab version aswell.
Any ideas on how to solve that problem?
Thanks in advance
MoritzMoritzhttps://it.mathworks.com/matlabcentral/profile/authors/15215120tag:it.mathworks.com,2005:Question/7262882021-01-25T10:21:55Z2021-01-26T13:45:17ZAbsence of PV array in Simulink (Matlab2020a)I have MATLAB 2020a. PV array is not present in the simulink library. Can anyone please explain if the name of module has been changed or is it not available anymore?
Is there any way to add PV array to the library somehow?Omais Abdur Rehmanhttps://it.mathworks.com/matlabcentral/profile/authors/21236305tag:it.mathworks.com,2005:Question/7273432021-01-26T12:31:09Z2021-01-26T13:44:45ZBatch scheduler or pick up the run after wall time expires or checkpoints Hi,
I have a matlab program which I submitted as sbatch file. However, the walltime for matlab license on supercomputer to which I submitted expires after 24hrs. My data is saved at each step so I am not worried of losing the data at any point. I am trying to find a way to start running the file after it left off on the for loop. For example, considering I am running a time program like, if my code ends at j = 45000 and j = 30000 after 24hrs, how should I restart again at i = 45001 and j = 30001. Any hints ?
for i= 1:100000
for j = 1:60000
code....
save(data)
end
endnlmhttps://it.mathworks.com/matlabcentral/profile/authors/2744890tag:it.mathworks.com,2005:Question/7273032021-01-26T11:34:58Z2021-01-26T13:43:12ZFix the function hlpi was told to write funciton for this: but it keeps saying something is wrong but i dont know what is wrong with it .
function [ arr ] =special_matrix( n )
if n>2
for i = 1:n
for j = 1:n
if mod(j,3)==0
arr(i,j)}=((i-1)*n+j}^j;
else
arr(i,j)={i-1}*n+j;
end
end
end
else
disp('Error; n must be greater than i')
end
end
Ainars Cernavskishttps://it.mathworks.com/matlabcentral/profile/authors/19751480tag:it.mathworks.com,2005:Question/7274182021-01-26T13:42:08Z2021-01-26T13:42:08ZWebwrite with .mlappinstall-file for artifactory-deploymentWe want to deploy updates for our appdesigner-apps (.exe as well as .mlappinstall) on our artifactory.
At the moment this is done manually. However, my goal is a matlab-script that
compiles the app
uploads it to its destination-folder on the artifactory.
My URL and login-informations are correct, I am able to deploy simple data (tested with a simple struct containing doubles and strings).
My question is, how to convert or pack an .mlappinstall for it to be sendable by webwrite.
I have found this FileExchange-solution for uploading to Dropbox via webwrite.
There they seem to encode an arbitrary file as char-array to put into webwrite. This naive approach doesn't work (it returns an empty char-array).
fid = fopen('myApp.mlappinstall', 'r');
data = char(fread(fid)');
Also, even if that would work, I would probably have difficulties to discern the correct MediaType and/or CharacterEncoding for the encoded .mlappinstall.
I would really appreciate suggestions for a proper workflow to do, what we want to achieve: compilation and artifactory-deployment of app-designer apps.
Also any help with encoding and sending apps or exe-files with webwrite would help us a lot.
Thank you.
Patrick Braunhttps://it.mathworks.com/matlabcentral/profile/authors/17273265