Author: PuTI
Clustering using Gower’s Distance
Hello all, I have a dataset that includes both categorical and numerical features, and I’m looking to perform clustering on it. I’ve read that Gower’s Distance (code is available) is suitable for handling mixed data types. However, I am getting an "isnan" error. How can I fix the problem? Thanks for the help.
DataSet = readtable("Test.xlsx", ‘ReadVariableNames’, true);
GowerDst = gower(DataSet);
[Idx, C] = kmedoids(DataSet, 2, ‘Distance’, GowerDst);
Error using isnan
Invalid data type. Argument must be numeric, char, or logical.
Error in kmedoids (line 220)
wasnan = any(isnan(X),2);
^^^^^^^^
Error in Gower_Distance (line 9)
[Idx, C] = kmedoids(DataSet, 2, ‘Distance’, GowerDst);Hello all, I have a dataset that includes both categorical and numerical features, and I’m looking to perform clustering on it. I’ve read that Gower’s Distance (code is available) is suitable for handling mixed data types. However, I am getting an "isnan" error. How can I fix the problem? Thanks for the help.
DataSet = readtable("Test.xlsx", ‘ReadVariableNames’, true);
GowerDst = gower(DataSet);
[Idx, C] = kmedoids(DataSet, 2, ‘Distance’, GowerDst);
Error using isnan
Invalid data type. Argument must be numeric, char, or logical.
Error in kmedoids (line 220)
wasnan = any(isnan(X),2);
^^^^^^^^
Error in Gower_Distance (line 9)
[Idx, C] = kmedoids(DataSet, 2, ‘Distance’, GowerDst); Hello all, I have a dataset that includes both categorical and numerical features, and I’m looking to perform clustering on it. I’ve read that Gower’s Distance (code is available) is suitable for handling mixed data types. However, I am getting an "isnan" error. How can I fix the problem? Thanks for the help.
DataSet = readtable("Test.xlsx", ‘ReadVariableNames’, true);
GowerDst = gower(DataSet);
[Idx, C] = kmedoids(DataSet, 2, ‘Distance’, GowerDst);
Error using isnan
Invalid data type. Argument must be numeric, char, or logical.
Error in kmedoids (line 220)
wasnan = any(isnan(X),2);
^^^^^^^^
Error in Gower_Distance (line 9)
[Idx, C] = kmedoids(DataSet, 2, ‘Distance’, GowerDst); gower’s distance, clustering MATLAB Answers — New Questions
No results from calculations in the command window
Hi there,
For some reason I am not getting any output results in the command window. I click on run and no results appear in the command window from my script. Nor, is there any results in the workspace – even though there a lots of calculations. I have restarted my computer and still there is no change. The last thing I was doing was trying to create a MATLAB function. Also, in the editor tab the option to create a new scipt is faded out. So I can’t access a new script. I have been using MATLAB online for months and I have never experienced this problem or any problem like it.
I am very confused and I do not know what is going wrong!
I hope someone can help?
Many thanks,
ScottHi there,
For some reason I am not getting any output results in the command window. I click on run and no results appear in the command window from my script. Nor, is there any results in the workspace – even though there a lots of calculations. I have restarted my computer and still there is no change. The last thing I was doing was trying to create a MATLAB function. Also, in the editor tab the option to create a new scipt is faded out. So I can’t access a new script. I have been using MATLAB online for months and I have never experienced this problem or any problem like it.
I am very confused and I do not know what is going wrong!
I hope someone can help?
Many thanks,
Scott Hi there,
For some reason I am not getting any output results in the command window. I click on run and no results appear in the command window from my script. Nor, is there any results in the workspace – even though there a lots of calculations. I have restarted my computer and still there is no change. The last thing I was doing was trying to create a MATLAB function. Also, in the editor tab the option to create a new scipt is faded out. So I can’t access a new script. I have been using MATLAB online for months and I have never experienced this problem or any problem like it.
I am very confused and I do not know what is going wrong!
I hope someone can help?
Many thanks,
Scott error, command window MATLAB Answers — New Questions
How to fix: Index Exceeds Matrix Dimensions
clear
clc
clf
%***************************************************
% constants
rad=pi/180;
eps0=8.85e-12;
mu0=4*pi*1e-7;
eta0=sqrt(mu0/eps0); % free space
c=1/sqrt(eps0*mu0);
%***************************************************
% variables
d=2.5e-3; % thickness of the sample
f1=1e9; df=9e6; f2=10e9; Nf=floor((f2-f1)/df)+1; % frequency range and
% load raw data
M1r = csvread(‘sample.dat’,4); % Read the data
P1r = csvread(‘sample1.dat’,2); % Read the data
P2r = csvread(‘sample2.dat’,2); % Read the data
Mag1=M1r(:,2);
Mag2=M1r(:,3);
Ph1=-unwrap(P1r(:,2),180);
Ph2=-unwrap(P2r(:,2),180);
%*****************************************
% freqyency loop begin
for it=1:Nf
f=f1+(it-1)*df;
Fr(it)=f;
Fghz(it)=f/1e9;
fghz=f/1e9;
Z0=eta0; W=2*pi*Fr(it); beta0=W/c;
%*******************************************
% combine magnitude and phase of the S11 and S21
R(it)=Mag1(it)*exp(j*Ph1(it)*rad);………………………………………………..error Index exceeds matrix dimensions.
R(it)=Mag1(it)*exp(j*Ph1(it)*rad);
T(it)=Mag2(it)*exp(j*Ph2(it)*rad);
% m loop begin
Max=0; % ———m value set up
itt=0;
for m=-Max:Max
itt=itt+1;
%***************************************************
% using formulas from Robust method
Tp=T(it);
Z21(it)=sqrt(((1+R(it))^2-Tp^2)/((1-R(it))^2-Tp^2));
Z22(it)=-sqrt(((1+R(it))^2-Tp^2)/((1-R(it))^2-Tp^2));
expinkd1(it)=Tp/(1-R(it)*(Z21(it)-1)/(Z21(it)+1));
expinkd2(it)=Tp/(1-R(it)*(Z22(it)-1)/(Z22(it)+1));
if abs(real(Z21(it)))>=0.005 & real(Z21(it))>=0
expinkd(it)=expinkd1(it);
Z2(it)=Z21(it);
end
if abs(real(Z21(it)))>=0.005 & real(Z21(it))<0
expinkd(it)=expinkd2(it);
Z2(it)=Z22(it);
end
if abs(real(Z21(it)))<0.005 & abs(expinkd1(it))<=1
expinkd(it)=expinkd1(it);
Z2(it)=Z21(it);
end
if abs(real(Z21(it)))<0.005 & abs(expinkd1(it))>1
expinkd(it)=expinkd2(it);
Z2(it)=Z22(it);
end
ni(it)=-1/(beta0*d)*j*real(log(expinkd(it))); % imag of n
nr(it,itt)=1/(beta0*d)*(imag(log(expinkd(it)))+2*m*pi); %real of n
n2(it,itt)=nr(it,itt)+ni(it);
Er2(it,itt)=n2(it,itt)/Z2(it);
Mr2(it,itt)=n2(it,itt)*Z2(it);
end % end of m loop
end % end of frequency loopclear
clc
clf
%***************************************************
% constants
rad=pi/180;
eps0=8.85e-12;
mu0=4*pi*1e-7;
eta0=sqrt(mu0/eps0); % free space
c=1/sqrt(eps0*mu0);
%***************************************************
% variables
d=2.5e-3; % thickness of the sample
f1=1e9; df=9e6; f2=10e9; Nf=floor((f2-f1)/df)+1; % frequency range and
% load raw data
M1r = csvread(‘sample.dat’,4); % Read the data
P1r = csvread(‘sample1.dat’,2); % Read the data
P2r = csvread(‘sample2.dat’,2); % Read the data
Mag1=M1r(:,2);
Mag2=M1r(:,3);
Ph1=-unwrap(P1r(:,2),180);
Ph2=-unwrap(P2r(:,2),180);
%*****************************************
% freqyency loop begin
for it=1:Nf
f=f1+(it-1)*df;
Fr(it)=f;
Fghz(it)=f/1e9;
fghz=f/1e9;
Z0=eta0; W=2*pi*Fr(it); beta0=W/c;
%*******************************************
% combine magnitude and phase of the S11 and S21
R(it)=Mag1(it)*exp(j*Ph1(it)*rad);………………………………………………..error Index exceeds matrix dimensions.
R(it)=Mag1(it)*exp(j*Ph1(it)*rad);
T(it)=Mag2(it)*exp(j*Ph2(it)*rad);
% m loop begin
Max=0; % ———m value set up
itt=0;
for m=-Max:Max
itt=itt+1;
%***************************************************
% using formulas from Robust method
Tp=T(it);
Z21(it)=sqrt(((1+R(it))^2-Tp^2)/((1-R(it))^2-Tp^2));
Z22(it)=-sqrt(((1+R(it))^2-Tp^2)/((1-R(it))^2-Tp^2));
expinkd1(it)=Tp/(1-R(it)*(Z21(it)-1)/(Z21(it)+1));
expinkd2(it)=Tp/(1-R(it)*(Z22(it)-1)/(Z22(it)+1));
if abs(real(Z21(it)))>=0.005 & real(Z21(it))>=0
expinkd(it)=expinkd1(it);
Z2(it)=Z21(it);
end
if abs(real(Z21(it)))>=0.005 & real(Z21(it))<0
expinkd(it)=expinkd2(it);
Z2(it)=Z22(it);
end
if abs(real(Z21(it)))<0.005 & abs(expinkd1(it))<=1
expinkd(it)=expinkd1(it);
Z2(it)=Z21(it);
end
if abs(real(Z21(it)))<0.005 & abs(expinkd1(it))>1
expinkd(it)=expinkd2(it);
Z2(it)=Z22(it);
end
ni(it)=-1/(beta0*d)*j*real(log(expinkd(it))); % imag of n
nr(it,itt)=1/(beta0*d)*(imag(log(expinkd(it)))+2*m*pi); %real of n
n2(it,itt)=nr(it,itt)+ni(it);
Er2(it,itt)=n2(it,itt)/Z2(it);
Mr2(it,itt)=n2(it,itt)*Z2(it);
end % end of m loop
end % end of frequency loop clear
clc
clf
%***************************************************
% constants
rad=pi/180;
eps0=8.85e-12;
mu0=4*pi*1e-7;
eta0=sqrt(mu0/eps0); % free space
c=1/sqrt(eps0*mu0);
%***************************************************
% variables
d=2.5e-3; % thickness of the sample
f1=1e9; df=9e6; f2=10e9; Nf=floor((f2-f1)/df)+1; % frequency range and
% load raw data
M1r = csvread(‘sample.dat’,4); % Read the data
P1r = csvread(‘sample1.dat’,2); % Read the data
P2r = csvread(‘sample2.dat’,2); % Read the data
Mag1=M1r(:,2);
Mag2=M1r(:,3);
Ph1=-unwrap(P1r(:,2),180);
Ph2=-unwrap(P2r(:,2),180);
%*****************************************
% freqyency loop begin
for it=1:Nf
f=f1+(it-1)*df;
Fr(it)=f;
Fghz(it)=f/1e9;
fghz=f/1e9;
Z0=eta0; W=2*pi*Fr(it); beta0=W/c;
%*******************************************
% combine magnitude and phase of the S11 and S21
R(it)=Mag1(it)*exp(j*Ph1(it)*rad);………………………………………………..error Index exceeds matrix dimensions.
R(it)=Mag1(it)*exp(j*Ph1(it)*rad);
T(it)=Mag2(it)*exp(j*Ph2(it)*rad);
% m loop begin
Max=0; % ———m value set up
itt=0;
for m=-Max:Max
itt=itt+1;
%***************************************************
% using formulas from Robust method
Tp=T(it);
Z21(it)=sqrt(((1+R(it))^2-Tp^2)/((1-R(it))^2-Tp^2));
Z22(it)=-sqrt(((1+R(it))^2-Tp^2)/((1-R(it))^2-Tp^2));
expinkd1(it)=Tp/(1-R(it)*(Z21(it)-1)/(Z21(it)+1));
expinkd2(it)=Tp/(1-R(it)*(Z22(it)-1)/(Z22(it)+1));
if abs(real(Z21(it)))>=0.005 & real(Z21(it))>=0
expinkd(it)=expinkd1(it);
Z2(it)=Z21(it);
end
if abs(real(Z21(it)))>=0.005 & real(Z21(it))<0
expinkd(it)=expinkd2(it);
Z2(it)=Z22(it);
end
if abs(real(Z21(it)))<0.005 & abs(expinkd1(it))<=1
expinkd(it)=expinkd1(it);
Z2(it)=Z21(it);
end
if abs(real(Z21(it)))<0.005 & abs(expinkd1(it))>1
expinkd(it)=expinkd2(it);
Z2(it)=Z22(it);
end
ni(it)=-1/(beta0*d)*j*real(log(expinkd(it))); % imag of n
nr(it,itt)=1/(beta0*d)*(imag(log(expinkd(it)))+2*m*pi); %real of n
n2(it,itt)=nr(it,itt)+ni(it);
Er2(it,itt)=n2(it,itt)/Z2(it);
Mr2(it,itt)=n2(it,itt)*Z2(it);
end % end of m loop
end % end of frequency loop index exceeds matrix dimensions. error in check2 (line 37) r(it)=mag1(it)*exp(j*ph1(it)*rad) MATLAB Answers — New Questions
Matlab freezes on startup
Hello all ,Matlab freezes on startup. It opens a file named dos.m, and from that point, I can neither run any script, set the path, nor even navigate to a folder. any idea ?Hello all ,Matlab freezes on startup. It opens a file named dos.m, and from that point, I can neither run any script, set the path, nor even navigate to a folder. any idea ? Hello all ,Matlab freezes on startup. It opens a file named dos.m, and from that point, I can neither run any script, set the path, nor even navigate to a folder. any idea ? transferred MATLAB Answers — New Questions
Dictionary to std::unordered_map in a mex file
I am using some c++ code with mex. I would like to pass in a dictionary of parameters, do some computation and create some vectors, and then return the results as a dictionary. Something like the following:
// test_mex.cpp
#include "mex.h"
void mexFunction(int N_output, mxArray *output[], int N_input, const mxArray *input[]) {
// Check input
if (N_input != 1) {
mexErrMsgIdAndTxt("MyClass:InvalidInput", "One input required.");
}
if (!mxIsClass(input[0], "dictionary")) {
mexErrMsgIdAndTxt("MATLAB:invalidInput", "Input must be a dictionary.");
}
// Convert to a std::unordered_map
std::unordered_map<std::string, double> params = input[0];
// Compute
std::unordered_map<std::string, std::vector<double>> out;
out["C"] = std::vector<double>(params["A"], 1.0);
// Convert back to a dictionary and return
output[0] = out;
}
Called with:
mex test_mex; test_mex(dictionary(["A", "B"], {100, 1020}));I am using some c++ code with mex. I would like to pass in a dictionary of parameters, do some computation and create some vectors, and then return the results as a dictionary. Something like the following:
// test_mex.cpp
#include "mex.h"
void mexFunction(int N_output, mxArray *output[], int N_input, const mxArray *input[]) {
// Check input
if (N_input != 1) {
mexErrMsgIdAndTxt("MyClass:InvalidInput", "One input required.");
}
if (!mxIsClass(input[0], "dictionary")) {
mexErrMsgIdAndTxt("MATLAB:invalidInput", "Input must be a dictionary.");
}
// Convert to a std::unordered_map
std::unordered_map<std::string, double> params = input[0];
// Compute
std::unordered_map<std::string, std::vector<double>> out;
out["C"] = std::vector<double>(params["A"], 1.0);
// Convert back to a dictionary and return
output[0] = out;
}
Called with:
mex test_mex; test_mex(dictionary(["A", "B"], {100, 1020})); I am using some c++ code with mex. I would like to pass in a dictionary of parameters, do some computation and create some vectors, and then return the results as a dictionary. Something like the following:
// test_mex.cpp
#include "mex.h"
void mexFunction(int N_output, mxArray *output[], int N_input, const mxArray *input[]) {
// Check input
if (N_input != 1) {
mexErrMsgIdAndTxt("MyClass:InvalidInput", "One input required.");
}
if (!mxIsClass(input[0], "dictionary")) {
mexErrMsgIdAndTxt("MATLAB:invalidInput", "Input must be a dictionary.");
}
// Convert to a std::unordered_map
std::unordered_map<std::string, double> params = input[0];
// Compute
std::unordered_map<std::string, std::vector<double>> out;
out["C"] = std::vector<double>(params["A"], 1.0);
// Convert back to a dictionary and return
output[0] = out;
}
Called with:
mex test_mex; test_mex(dictionary(["A", "B"], {100, 1020})); mex, dictionary MATLAB Answers — New Questions
How to have smithPlot with outer area with white colour?
Hi
I was using this code for years giving me perfectly fine smith plots with white colour )inner, outer and background).
figure
sm = smithplot(gca);
hold on
% Set the background color of the outer area to white
ax = gca;
set(gcf, ‘Color’, ‘white’);
% Rest of your code
sm.ArcTickLabelVisible = 0;
sm.CircleTickLabelVisible = 0;
sm.Marker = {‘+’};
sm.GridBackgroundColor = ‘w’;
sm.TitleTopFontSizeMultiplier = 1.75;
sm.GridLineWidth = 1;
I recently upgraded to MATLAB R2024a, and same code gives me smith plot with grau outer area, although I command for a white one.
Any recommnedation on this ?
ThanksHi
I was using this code for years giving me perfectly fine smith plots with white colour )inner, outer and background).
figure
sm = smithplot(gca);
hold on
% Set the background color of the outer area to white
ax = gca;
set(gcf, ‘Color’, ‘white’);
% Rest of your code
sm.ArcTickLabelVisible = 0;
sm.CircleTickLabelVisible = 0;
sm.Marker = {‘+’};
sm.GridBackgroundColor = ‘w’;
sm.TitleTopFontSizeMultiplier = 1.75;
sm.GridLineWidth = 1;
I recently upgraded to MATLAB R2024a, and same code gives me smith plot with grau outer area, although I command for a white one.
Any recommnedation on this ?
Thanks Hi
I was using this code for years giving me perfectly fine smith plots with white colour )inner, outer and background).
figure
sm = smithplot(gca);
hold on
% Set the background color of the outer area to white
ax = gca;
set(gcf, ‘Color’, ‘white’);
% Rest of your code
sm.ArcTickLabelVisible = 0;
sm.CircleTickLabelVisible = 0;
sm.Marker = {‘+’};
sm.GridBackgroundColor = ‘w’;
sm.TitleTopFontSizeMultiplier = 1.75;
sm.GridLineWidth = 1;
I recently upgraded to MATLAB R2024a, and same code gives me smith plot with grau outer area, although I command for a white one.
Any recommnedation on this ?
Thanks smithplot, figure, rf MATLAB Answers — New Questions
Why is the smoothing effect of【 pcolor() shading interp 】worse on 2025a than the old version 2023b
When I updated the latest 2025a, I tried to draw a picture with pcolor() and found that pixel blocks appeared on the picture drawn by the 2025a version, but not in the 2023b version, so I was a little confused why?
The code is as follows,and the data package and operation results are shown in the attachment
clc;clear;close all
load(‘test.mat’)
figure;
figWidth = 14;
figHeight = figWidth * (10 – (-5)) / (160 – 130);
set(gcf, ‘Units’, ‘centimeters’, ‘Position’, [10 10 figWidth figHeight]);
set(gcf, ‘Color’, ‘white’, ‘InvertHardcopy’, ‘off’);
h = pcolor(a, b, d);
shading interp
set(h, ‘EdgeColor’, ‘none’)
caxis([-1.2 1.2])
set(gca, ‘YDir’, ‘reverse’,’TickDir’,’out’, ‘FontSize’, 8, ‘Box’, ‘on’,’FontName’,’Arial’)
colorbar(‘Location’, ‘eastoutside’,’FontName’,’Arial’,’FontWeight’,’normal’);
exportgraphics(gca,’test.pdf’,’BackgroundColor’,’none’,’ContentType’,’vector’,’Resolution’,600)
close allWhen I updated the latest 2025a, I tried to draw a picture with pcolor() and found that pixel blocks appeared on the picture drawn by the 2025a version, but not in the 2023b version, so I was a little confused why?
The code is as follows,and the data package and operation results are shown in the attachment
clc;clear;close all
load(‘test.mat’)
figure;
figWidth = 14;
figHeight = figWidth * (10 – (-5)) / (160 – 130);
set(gcf, ‘Units’, ‘centimeters’, ‘Position’, [10 10 figWidth figHeight]);
set(gcf, ‘Color’, ‘white’, ‘InvertHardcopy’, ‘off’);
h = pcolor(a, b, d);
shading interp
set(h, ‘EdgeColor’, ‘none’)
caxis([-1.2 1.2])
set(gca, ‘YDir’, ‘reverse’,’TickDir’,’out’, ‘FontSize’, 8, ‘Box’, ‘on’,’FontName’,’Arial’)
colorbar(‘Location’, ‘eastoutside’,’FontName’,’Arial’,’FontWeight’,’normal’);
exportgraphics(gca,’test.pdf’,’BackgroundColor’,’none’,’ContentType’,’vector’,’Resolution’,600)
close all When I updated the latest 2025a, I tried to draw a picture with pcolor() and found that pixel blocks appeared on the picture drawn by the 2025a version, but not in the 2023b version, so I was a little confused why?
The code is as follows,and the data package and operation results are shown in the attachment
clc;clear;close all
load(‘test.mat’)
figure;
figWidth = 14;
figHeight = figWidth * (10 – (-5)) / (160 – 130);
set(gcf, ‘Units’, ‘centimeters’, ‘Position’, [10 10 figWidth figHeight]);
set(gcf, ‘Color’, ‘white’, ‘InvertHardcopy’, ‘off’);
h = pcolor(a, b, d);
shading interp
set(h, ‘EdgeColor’, ‘none’)
caxis([-1.2 1.2])
set(gca, ‘YDir’, ‘reverse’,’TickDir’,’out’, ‘FontSize’, 8, ‘Box’, ‘on’,’FontName’,’Arial’)
colorbar(‘Location’, ‘eastoutside’,’FontName’,’Arial’,’FontWeight’,’normal’);
exportgraphics(gca,’test.pdf’,’BackgroundColor’,’none’,’ContentType’,’vector’,’Resolution’,600)
close all pcolor, resolution MATLAB Answers — New Questions
How to leave a Microsoft family group – Microsoft Support
How to remove members from your family group when you’re on your PC, including adult and child accounts.
Why Matlab in 2025, instead of Julia etc.?
I’m planning to start a personal scientific software project. I used to be familiar with Matlab (quite some time ago), so Matlab would be my first choice. But I keep hearing that Matlab is old stuff and I should use Julia or something like that. I wouldn’t find learning Julia difficult, so familiarity with Matlab is not an important factor. Neither is cost, because I can afford a home license for Matlab, Simulink and a few toolboxes. So I’m thinking. Please give me your input! Why should I use Matlab in 2025 instead of alternatives?I’m planning to start a personal scientific software project. I used to be familiar with Matlab (quite some time ago), so Matlab would be my first choice. But I keep hearing that Matlab is old stuff and I should use Julia or something like that. I wouldn’t find learning Julia difficult, so familiarity with Matlab is not an important factor. Neither is cost, because I can afford a home license for Matlab, Simulink and a few toolboxes. So I’m thinking. Please give me your input! Why should I use Matlab in 2025 instead of alternatives? I’m planning to start a personal scientific software project. I used to be familiar with Matlab (quite some time ago), so Matlab would be my first choice. But I keep hearing that Matlab is old stuff and I should use Julia or something like that. I wouldn’t find learning Julia difficult, so familiarity with Matlab is not an important factor. Neither is cost, because I can afford a home license for Matlab, Simulink and a few toolboxes. So I’m thinking. Please give me your input! Why should I use Matlab in 2025 instead of alternatives? matlab, julia MATLAB Answers — New Questions
Function to copy to clickboard in App Designer?
I am making an application that outputs results in Edit Fields (both text and numeric). I would like to add a function that automatically copies the contents of an Edit Field to the clipboard when the Edit Field is selected (clicked). However, I do not see a callback function for Edit Fields like "ClickedFcn" for Drop Down lists.
Is it possible to do this directly or perhaps via some workaround?I am making an application that outputs results in Edit Fields (both text and numeric). I would like to add a function that automatically copies the contents of an Edit Field to the clipboard when the Edit Field is selected (clicked). However, I do not see a callback function for Edit Fields like "ClickedFcn" for Drop Down lists.
Is it possible to do this directly or perhaps via some workaround? I am making an application that outputs results in Edit Fields (both text and numeric). I would like to add a function that automatically copies the contents of an Edit Field to the clipboard when the Edit Field is selected (clicked). However, I do not see a callback function for Edit Fields like "ClickedFcn" for Drop Down lists.
Is it possible to do this directly or perhaps via some workaround? appdesigner, clickedfcn, clipboard, callback MATLAB Answers — New Questions
Where to get a zip code for free 30 days trial
Hi I am a student at University of Johannesburg. I created the MATLAB account online. I want to start the 30 day free trial but when I tap to student trial version, I am required to type in a zip code. Please help because I don not know the zip code.Hi I am a student at University of Johannesburg. I created the MATLAB account online. I want to start the 30 day free trial but when I tap to student trial version, I am required to type in a zip code. Please help because I don not know the zip code. Hi I am a student at University of Johannesburg. I created the MATLAB account online. I want to start the 30 day free trial but when I tap to student trial version, I am required to type in a zip code. Please help because I don not know the zip code. power_electronics_control MATLAB Answers — New Questions
Random lags while running app
I have an App Designed application that collects data from an Arduino Pico.
The Pico runs individual trials with accurate to submillisecond timing. MATLAB starts each trial as soon as the previous one is complete. Data is saved in tables as I found that writing to disk after each trial took too long. Even so, the time between trials is longer than it should be AND it can be extremely long on occasion. I’ve plotted each trial duration and the timing of the end of one to the start of the next. Any ideas as to why MATLAB occasionally takes long breaks? I’ve tried clearing variables between each trial (doesn’t seem to affect my app tables). Removed calls to get time of day (useing Pico Timer for data) various other attemps with Profiler but no luck since the error is rare. Copilot wasn’t much help either.
I tried updating to version R2025a and that was much worse!
Any help much appreciated. Code for the app is here, it’s big:
https://drive.google.com/file/d/1mwCtRJ-l_2fhk26JYzz2IxidDqkU3IV1/view?usp=sharingI have an App Designed application that collects data from an Arduino Pico.
The Pico runs individual trials with accurate to submillisecond timing. MATLAB starts each trial as soon as the previous one is complete. Data is saved in tables as I found that writing to disk after each trial took too long. Even so, the time between trials is longer than it should be AND it can be extremely long on occasion. I’ve plotted each trial duration and the timing of the end of one to the start of the next. Any ideas as to why MATLAB occasionally takes long breaks? I’ve tried clearing variables between each trial (doesn’t seem to affect my app tables). Removed calls to get time of day (useing Pico Timer for data) various other attemps with Profiler but no luck since the error is rare. Copilot wasn’t much help either.
I tried updating to version R2025a and that was much worse!
Any help much appreciated. Code for the app is here, it’s big:
https://drive.google.com/file/d/1mwCtRJ-l_2fhk26JYzz2IxidDqkU3IV1/view?usp=sharing I have an App Designed application that collects data from an Arduino Pico.
The Pico runs individual trials with accurate to submillisecond timing. MATLAB starts each trial as soon as the previous one is complete. Data is saved in tables as I found that writing to disk after each trial took too long. Even so, the time between trials is longer than it should be AND it can be extremely long on occasion. I’ve plotted each trial duration and the timing of the end of one to the start of the next. Any ideas as to why MATLAB occasionally takes long breaks? I’ve tried clearing variables between each trial (doesn’t seem to affect my app tables). Removed calls to get time of day (useing Pico Timer for data) various other attemps with Profiler but no luck since the error is rare. Copilot wasn’t much help either.
I tried updating to version R2025a and that was much worse!
Any help much appreciated. Code for the app is here, it’s big:
https://drive.google.com/file/d/1mwCtRJ-l_2fhk26JYzz2IxidDqkU3IV1/view?usp=sharing lagging MATLAB Answers — New Questions
Gradient descent with a simple function
Hi everyone, I am currently practicing this method on a simple function, however I keep getting this error and I do not know how to fix it.
Here is my programe:
fplot(@(x)myfun(x),[-10,10]);
alpha = 0.01;
x0 = -5;
% ——-using GD———————-
[x grad] = gradient(alpha,x0)
% hold on
% figure;
fprintf(‘x = %fn’,x);
fprintf(‘grad = %fn’,grad);
% ——————————
function f = myfun(x)
f = x^2+5*sin(x);
end
function [x,grad] = gradient(alpha,x0)
grad = 2*x0+5*cos(x0);
x = x0;
for i = 0:50
x = x – alpha*grad;
if abs(grad(x))< 0.01
break
display(x);
% grad = grad(x);
end
end
Here is the error that I got
Array indices must be positive integers or logical values.
Error in gradient (line 6)
if abs(grad(x))< 0.01
Error in Gradient_descent_1 (line 5)
[x grad] = gradient(alpha,x0)Hi everyone, I am currently practicing this method on a simple function, however I keep getting this error and I do not know how to fix it.
Here is my programe:
fplot(@(x)myfun(x),[-10,10]);
alpha = 0.01;
x0 = -5;
% ——-using GD———————-
[x grad] = gradient(alpha,x0)
% hold on
% figure;
fprintf(‘x = %fn’,x);
fprintf(‘grad = %fn’,grad);
% ——————————
function f = myfun(x)
f = x^2+5*sin(x);
end
function [x,grad] = gradient(alpha,x0)
grad = 2*x0+5*cos(x0);
x = x0;
for i = 0:50
x = x – alpha*grad;
if abs(grad(x))< 0.01
break
display(x);
% grad = grad(x);
end
end
Here is the error that I got
Array indices must be positive integers or logical values.
Error in gradient (line 6)
if abs(grad(x))< 0.01
Error in Gradient_descent_1 (line 5)
[x grad] = gradient(alpha,x0) Hi everyone, I am currently practicing this method on a simple function, however I keep getting this error and I do not know how to fix it.
Here is my programe:
fplot(@(x)myfun(x),[-10,10]);
alpha = 0.01;
x0 = -5;
% ——-using GD———————-
[x grad] = gradient(alpha,x0)
% hold on
% figure;
fprintf(‘x = %fn’,x);
fprintf(‘grad = %fn’,grad);
% ——————————
function f = myfun(x)
f = x^2+5*sin(x);
end
function [x,grad] = gradient(alpha,x0)
grad = 2*x0+5*cos(x0);
x = x0;
for i = 0:50
x = x – alpha*grad;
if abs(grad(x))< 0.01
break
display(x);
% grad = grad(x);
end
end
Here is the error that I got
Array indices must be positive integers or logical values.
Error in gradient (line 6)
if abs(grad(x))< 0.01
Error in Gradient_descent_1 (line 5)
[x grad] = gradient(alpha,x0) machine learning MATLAB Answers — New Questions
Create an index based Schmitt Trigger
Hello, I have a function that mimics a Schmitt Trigger to translate an analog sine wave into a digital square wave. So far, I have accomplished this with a for loop and the function works as planned. However, since I have a significant amount of data to process, I would like to do this index based for speed. I cannot think of a way to make this index based so the function performes faster.
My function is below, any suggestions on how to make this index based? Is it possible?
Thanks.
function [y] = Schmitt_Trigger(x,tL,tH)
%x is the input array that contains the analog sine wave to process.
%tL is the lower bound of the hysteresis and tH is the upper bound.
N = length(x);
y = zeros(1,N);
for i = 2:N
y(i) = y(i-1);
if y(i-1) == 0 && x(i)>tH
y(i) = 1;
end
if y(i-1) == 1 && x(i)<tL
y(i) = 0;
end
end
endHello, I have a function that mimics a Schmitt Trigger to translate an analog sine wave into a digital square wave. So far, I have accomplished this with a for loop and the function works as planned. However, since I have a significant amount of data to process, I would like to do this index based for speed. I cannot think of a way to make this index based so the function performes faster.
My function is below, any suggestions on how to make this index based? Is it possible?
Thanks.
function [y] = Schmitt_Trigger(x,tL,tH)
%x is the input array that contains the analog sine wave to process.
%tL is the lower bound of the hysteresis and tH is the upper bound.
N = length(x);
y = zeros(1,N);
for i = 2:N
y(i) = y(i-1);
if y(i-1) == 0 && x(i)>tH
y(i) = 1;
end
if y(i-1) == 1 && x(i)<tL
y(i) = 0;
end
end
end Hello, I have a function that mimics a Schmitt Trigger to translate an analog sine wave into a digital square wave. So far, I have accomplished this with a for loop and the function works as planned. However, since I have a significant amount of data to process, I would like to do this index based for speed. I cannot think of a way to make this index based so the function performes faster.
My function is below, any suggestions on how to make this index based? Is it possible?
Thanks.
function [y] = Schmitt_Trigger(x,tL,tH)
%x is the input array that contains the analog sine wave to process.
%tL is the lower bound of the hysteresis and tH is the upper bound.
N = length(x);
y = zeros(1,N);
for i = 2:N
y(i) = y(i-1);
if y(i-1) == 0 && x(i)>tH
y(i) = 1;
end
if y(i-1) == 1 && x(i)<tL
y(i) = 0;
end
end
end matlab, schmitt trigger, speed, index based MATLAB Answers — New Questions
Motion analysis in captured video
I have a camera mounted on a car capturing video. The car starts and stops frequently. I want to figure out when the car stops and starts. There is enough disturbance in the environment with uneven ground and even a breeze can cause huge changes in the environment. Just looking for difference from frame to frame does not give me what I need. I have tried that already. There are no markers either to distinguish when the car stops. This is not inline analysis. I have to do this offline.
Any ideas to try would be greatly appreciated.I have a camera mounted on a car capturing video. The car starts and stops frequently. I want to figure out when the car stops and starts. There is enough disturbance in the environment with uneven ground and even a breeze can cause huge changes in the environment. Just looking for difference from frame to frame does not give me what I need. I have tried that already. There are no markers either to distinguish when the car stops. This is not inline analysis. I have to do this offline.
Any ideas to try would be greatly appreciated. I have a camera mounted on a car capturing video. The car starts and stops frequently. I want to figure out when the car stops and starts. There is enough disturbance in the environment with uneven ground and even a breeze can cause huge changes in the environment. Just looking for difference from frame to frame does not give me what I need. I have tried that already. There are no markers either to distinguish when the car stops. This is not inline analysis. I have to do this offline.
Any ideas to try would be greatly appreciated. motion, image analysis, image processing, video analysis MATLAB Answers — New Questions
Microsoft Media Foundation while using audioread
Hi,
I have a brand new PC at my lab where Windows 10 Pro Education N (Version 10.0 (Build 19042)) is installed. I already checked for every update and Windows Update says all is updated, however I’m getting the following error on Matlab (9.5.0.1586782 (R2018b) Update 8):
"Error using audioread (line 104)
Audio file I/O requires Microsoft(R) Media Foundation.
Install this on your system and restart MATLAB."
I already searched for the Microsoft Media Foundation installer and I’m getting an error saying that the PC is incompatible with that installation. I believe that is due to the fact that the PC is already updated according to what I found on the internet.
Does anybody know a permanent solution for this? I know I probably should contact to my university IT department since computer’s updates are linked to the university, but first I wanted to ask here since you know better how to deal with Matlab.
Thanks in advance,
Javi.Hi,
I have a brand new PC at my lab where Windows 10 Pro Education N (Version 10.0 (Build 19042)) is installed. I already checked for every update and Windows Update says all is updated, however I’m getting the following error on Matlab (9.5.0.1586782 (R2018b) Update 8):
"Error using audioread (line 104)
Audio file I/O requires Microsoft(R) Media Foundation.
Install this on your system and restart MATLAB."
I already searched for the Microsoft Media Foundation installer and I’m getting an error saying that the PC is incompatible with that installation. I believe that is due to the fact that the PC is already updated according to what I found on the internet.
Does anybody know a permanent solution for this? I know I probably should contact to my university IT department since computer’s updates are linked to the university, but first I wanted to ask here since you know better how to deal with Matlab.
Thanks in advance,
Javi. Hi,
I have a brand new PC at my lab where Windows 10 Pro Education N (Version 10.0 (Build 19042)) is installed. I already checked for every update and Windows Update says all is updated, however I’m getting the following error on Matlab (9.5.0.1586782 (R2018b) Update 8):
"Error using audioread (line 104)
Audio file I/O requires Microsoft(R) Media Foundation.
Install this on your system and restart MATLAB."
I already searched for the Microsoft Media Foundation installer and I’m getting an error saying that the PC is incompatible with that installation. I believe that is due to the fact that the PC is already updated according to what I found on the internet.
Does anybody know a permanent solution for this? I know I probably should contact to my university IT department since computer’s updates are linked to the university, but first I wanted to ask here since you know better how to deal with Matlab.
Thanks in advance,
Javi. microsoft media foundation, microsoft, media foundation, audioread error MATLAB Answers — New Questions
Why can’t i draw pcolor() plots anymore with Matlab 2025a?
Hi, i recently upgraded from 2021b to 2025a and now the canvas of my figure is white and Matlab throws the warning:
Warning: An error occurred while drawing the scene: Error in web draw traversal: RangeError: Array buffer allocation failed
For better understanding:
I call the pcolor() function and the figure out of a Matlab app. Plotting that into the UIAxes in Matlab 2021b gave me the same error. My workaround was to create a standard figure and plot into this. Now with Matlab 2025a, i do not have this workaround anymore and i get the same error either way.Hi, i recently upgraded from 2021b to 2025a and now the canvas of my figure is white and Matlab throws the warning:
Warning: An error occurred while drawing the scene: Error in web draw traversal: RangeError: Array buffer allocation failed
For better understanding:
I call the pcolor() function and the figure out of a Matlab app. Plotting that into the UIAxes in Matlab 2021b gave me the same error. My workaround was to create a standard figure and plot into this. Now with Matlab 2025a, i do not have this workaround anymore and i get the same error either way. Hi, i recently upgraded from 2021b to 2025a and now the canvas of my figure is white and Matlab throws the warning:
Warning: An error occurred while drawing the scene: Error in web draw traversal: RangeError: Array buffer allocation failed
For better understanding:
I call the pcolor() function and the figure out of a Matlab app. Plotting that into the UIAxes in Matlab 2021b gave me the same error. My workaround was to create a standard figure and plot into this. Now with Matlab 2025a, i do not have this workaround anymore and i get the same error either way. figure MATLAB Answers — New Questions
Question about entry-wise product of general plant and weighting function matrix using Hinfstruct for multi-objective design
When I obtained the transfer matrix T from exogenous input w to real (unweighted) output z, entrywise product of matrix T and weighted transfer function matrix W is expected to be calculated and optimized. I use connect command to obtain T, which is a 4*2 transfer function matrix with adjustable parameters, reflecting the tranfer relation from input w=[Pref, wg]’ to output z=[Pref-p, p, wu, q+V/Dq]’. W is a constant transfer function matrix. Direct entrywise product of T and W cannot be implemented with MATLAB. As mentioned in P. Apkarian’s paper "Structured Hinfinity Synthesis in MATLAB", it should be formulated as Standard Form like H=blkdiag(Tij*Wij), then "Hinfstruct" can be used on H to find the tuned controllers. So I use the command like this:
H=blkdiag(T(1,1)*W11, T(1,2)*W12, T(2,1)*W21, T(2,2)*W22, T(3,1)*W31, T(3,2)*W32, T(4,1)*W41, T(4,2)*W42);
T = hinfstruct(H,opt);
However, above code cannot get the correct results. The reason I think should be the increased system order. For example, original system T has only 12 states. But system H has 103 states, where 7 states are from weighting fucntions, and the remaining 96 states are the 8 repeated states of system T, that is, 12*8=96.
Take a more realistic case with official Matlab’s "hinfstruct" example as follows. The goal is to minimize the H-infinity norm from [r, nw]’ to [y, ew]’. An important difference is that there is no entrywise product of Tij and Wij. It means the goal is to minimize 4 transfer functions: T(y,r), T(y,nw), T(ew,r), T(ew,nw).
The official command is given as follows, which works well:
T0 = connect(G,Wn,We,C0,F0,Sum1,Sum2,{‘r’,’nw’},{‘y’,’ew’});
T = hinfstruct(T0);
If I want to formulate the above 4 optimization goals T(y,r), T(y,nw), T(ew,r), T(ew,nw) into Standard From (diagnol form), I revise the above code as follows:
T0 = connect(G,Wn,We,C0,F0,Sum1,Sum2,{‘r’,’nw’},{‘y’,’ew’});
T0_revised = blkdiag(T0(1,1),T0(1,2),T0(2,1),T0(2,2));
T = hinfstruct(T0_revised);
It also cannot operate correctly. Only revise it as follows can work:
T0 = connect(G,Wn,We,C0,F0,Sum1,Sum2,{‘r’,’nw’},{‘y’,’ew’});
T0_revised=blkdiag(1,LS)*T0*blkdiag(1,1/LS);
T = hinfstruct(T0_revised,opt);
But it is still not the entry-wise product case, just the traditonal single transfer function connection as shown in the above figure.
Therefore, could you share your idea about this solution then I can learn based on it, and further do more improvement. I am looking forward to your reply. Thanks a lot for your help!When I obtained the transfer matrix T from exogenous input w to real (unweighted) output z, entrywise product of matrix T and weighted transfer function matrix W is expected to be calculated and optimized. I use connect command to obtain T, which is a 4*2 transfer function matrix with adjustable parameters, reflecting the tranfer relation from input w=[Pref, wg]’ to output z=[Pref-p, p, wu, q+V/Dq]’. W is a constant transfer function matrix. Direct entrywise product of T and W cannot be implemented with MATLAB. As mentioned in P. Apkarian’s paper "Structured Hinfinity Synthesis in MATLAB", it should be formulated as Standard Form like H=blkdiag(Tij*Wij), then "Hinfstruct" can be used on H to find the tuned controllers. So I use the command like this:
H=blkdiag(T(1,1)*W11, T(1,2)*W12, T(2,1)*W21, T(2,2)*W22, T(3,1)*W31, T(3,2)*W32, T(4,1)*W41, T(4,2)*W42);
T = hinfstruct(H,opt);
However, above code cannot get the correct results. The reason I think should be the increased system order. For example, original system T has only 12 states. But system H has 103 states, where 7 states are from weighting fucntions, and the remaining 96 states are the 8 repeated states of system T, that is, 12*8=96.
Take a more realistic case with official Matlab’s "hinfstruct" example as follows. The goal is to minimize the H-infinity norm from [r, nw]’ to [y, ew]’. An important difference is that there is no entrywise product of Tij and Wij. It means the goal is to minimize 4 transfer functions: T(y,r), T(y,nw), T(ew,r), T(ew,nw).
The official command is given as follows, which works well:
T0 = connect(G,Wn,We,C0,F0,Sum1,Sum2,{‘r’,’nw’},{‘y’,’ew’});
T = hinfstruct(T0);
If I want to formulate the above 4 optimization goals T(y,r), T(y,nw), T(ew,r), T(ew,nw) into Standard From (diagnol form), I revise the above code as follows:
T0 = connect(G,Wn,We,C0,F0,Sum1,Sum2,{‘r’,’nw’},{‘y’,’ew’});
T0_revised = blkdiag(T0(1,1),T0(1,2),T0(2,1),T0(2,2));
T = hinfstruct(T0_revised);
It also cannot operate correctly. Only revise it as follows can work:
T0 = connect(G,Wn,We,C0,F0,Sum1,Sum2,{‘r’,’nw’},{‘y’,’ew’});
T0_revised=blkdiag(1,LS)*T0*blkdiag(1,1/LS);
T = hinfstruct(T0_revised,opt);
But it is still not the entry-wise product case, just the traditonal single transfer function connection as shown in the above figure.
Therefore, could you share your idea about this solution then I can learn based on it, and further do more improvement. I am looking forward to your reply. Thanks a lot for your help! When I obtained the transfer matrix T from exogenous input w to real (unweighted) output z, entrywise product of matrix T and weighted transfer function matrix W is expected to be calculated and optimized. I use connect command to obtain T, which is a 4*2 transfer function matrix with adjustable parameters, reflecting the tranfer relation from input w=[Pref, wg]’ to output z=[Pref-p, p, wu, q+V/Dq]’. W is a constant transfer function matrix. Direct entrywise product of T and W cannot be implemented with MATLAB. As mentioned in P. Apkarian’s paper "Structured Hinfinity Synthesis in MATLAB", it should be formulated as Standard Form like H=blkdiag(Tij*Wij), then "Hinfstruct" can be used on H to find the tuned controllers. So I use the command like this:
H=blkdiag(T(1,1)*W11, T(1,2)*W12, T(2,1)*W21, T(2,2)*W22, T(3,1)*W31, T(3,2)*W32, T(4,1)*W41, T(4,2)*W42);
T = hinfstruct(H,opt);
However, above code cannot get the correct results. The reason I think should be the increased system order. For example, original system T has only 12 states. But system H has 103 states, where 7 states are from weighting fucntions, and the remaining 96 states are the 8 repeated states of system T, that is, 12*8=96.
Take a more realistic case with official Matlab’s "hinfstruct" example as follows. The goal is to minimize the H-infinity norm from [r, nw]’ to [y, ew]’. An important difference is that there is no entrywise product of Tij and Wij. It means the goal is to minimize 4 transfer functions: T(y,r), T(y,nw), T(ew,r), T(ew,nw).
The official command is given as follows, which works well:
T0 = connect(G,Wn,We,C0,F0,Sum1,Sum2,{‘r’,’nw’},{‘y’,’ew’});
T = hinfstruct(T0);
If I want to formulate the above 4 optimization goals T(y,r), T(y,nw), T(ew,r), T(ew,nw) into Standard From (diagnol form), I revise the above code as follows:
T0 = connect(G,Wn,We,C0,F0,Sum1,Sum2,{‘r’,’nw’},{‘y’,’ew’});
T0_revised = blkdiag(T0(1,1),T0(1,2),T0(2,1),T0(2,2));
T = hinfstruct(T0_revised);
It also cannot operate correctly. Only revise it as follows can work:
T0 = connect(G,Wn,We,C0,F0,Sum1,Sum2,{‘r’,’nw’},{‘y’,’ew’});
T0_revised=blkdiag(1,LS)*T0*blkdiag(1,1/LS);
T = hinfstruct(T0_revised,opt);
But it is still not the entry-wise product case, just the traditonal single transfer function connection as shown in the above figure.
Therefore, could you share your idea about this solution then I can learn based on it, and further do more improvement. I am looking forward to your reply. Thanks a lot for your help! hinfstruct, robust control, control system toolbox MATLAB Answers — New Questions
Variable might be set by a nonscalar (three variables in pythagorean triplet)
Hi everyone,
Im working for project euler and I try to do #9 (Special Pythagorean Triplet). I have encountered couples of errors, one of which is something that occurs from my trying to make 3 arrays probably, some of them are named Variable might be set by a nonscalar and other errors which I don’t understand.
function y = pythtrip(a,b,c)
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
y = a*b*c;
a = 0:750;
b = 0:750;
c = 0:750;
while (a>b) && b>c && (a^2)+(b^2)==(c^2) && a+b+c == 1000;
pythtrip(a,b,c)
y;
endHi everyone,
Im working for project euler and I try to do #9 (Special Pythagorean Triplet). I have encountered couples of errors, one of which is something that occurs from my trying to make 3 arrays probably, some of them are named Variable might be set by a nonscalar and other errors which I don’t understand.
function y = pythtrip(a,b,c)
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
y = a*b*c;
a = 0:750;
b = 0:750;
c = 0:750;
while (a>b) && b>c && (a^2)+(b^2)==(c^2) && a+b+c == 1000;
pythtrip(a,b,c)
y;
end Hi everyone,
Im working for project euler and I try to do #9 (Special Pythagorean Triplet). I have encountered couples of errors, one of which is something that occurs from my trying to make 3 arrays probably, some of them are named Variable might be set by a nonscalar and other errors which I don’t understand.
function y = pythtrip(a,b,c)
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
y = a*b*c;
a = 0:750;
b = 0:750;
c = 0:750;
while (a>b) && b>c && (a^2)+(b^2)==(c^2) && a+b+c == 1000;
pythtrip(a,b,c)
y;
end project_euler, pythagorean triplet, arrays, while loop, function MATLAB Answers — New Questions
Trying to determine locations of markers in image
I’m trying to obtain the pixel coordinates of the dot pattern image data that is stored in the attached file; I’m using this image to spatially calibrate my camera image. Is there a way to automate the detection of these dots? Thanks in advance for any guidance.I’m trying to obtain the pixel coordinates of the dot pattern image data that is stored in the attached file; I’m using this image to spatially calibrate my camera image. Is there a way to automate the detection of these dots? Thanks in advance for any guidance. I’m trying to obtain the pixel coordinates of the dot pattern image data that is stored in the attached file; I’m using this image to spatially calibrate my camera image. Is there a way to automate the detection of these dots? Thanks in advance for any guidance. image analysis, feature detection, spatial calibration MATLAB Answers — New Questions