Tag Archives: matlab
Arduino Mega interfacing problem
I’m using matlab R2013a,I have installed the arduino package suggested by Matlab Websit,when I connect the arduino and type a=arduino in command,I got error as,
>> a = arduino
Undefined function or variable ‘arduino’.I’m using matlab R2013a,I have installed the arduino package suggested by Matlab Websit,when I connect the arduino and type a=arduino in command,I got error as,
>> a = arduino
Undefined function or variable ‘arduino’. I’m using matlab R2013a,I have installed the arduino package suggested by Matlab Websit,when I connect the arduino and type a=arduino in command,I got error as,
>> a = arduino
Undefined function or variable ‘arduino’. arduino, error MATLAB Answers — New Questions
For and While loops
How do I use Embedded “For” or “While” loops to scan through an image in MATLAB?How do I use Embedded “For” or “While” loops to scan through an image in MATLAB? How do I use Embedded “For” or “While” loops to scan through an image in MATLAB? loops MATLAB Answers — New Questions
Set EOIMode using VisaDev to avoid error from *IDN?
It appears that the Visadev function performs a *IDN? when trying to open the connection to a GPIB instrument. This allows it to populate the the information such as model, etc. The issue is that some instruments do not support *IDN? and of those instruments there are some that need the EOIMode set to off in order to function correctly.
So is there a way to suppress sending the *IDN? when using the visadev or is there a way to specify the identity command it is using? Also, is there a way to set the EOIMode before calling visadev? Because it seems like the only way this works now is that you call visadev to connect to the device, it errors out because it needs EOIMode off first and it did not understand what *IDN? command was. At this point you would have to clear the error on the instrument caused by sending an unknown command each time a connection was made.It appears that the Visadev function performs a *IDN? when trying to open the connection to a GPIB instrument. This allows it to populate the the information such as model, etc. The issue is that some instruments do not support *IDN? and of those instruments there are some that need the EOIMode set to off in order to function correctly.
So is there a way to suppress sending the *IDN? when using the visadev or is there a way to specify the identity command it is using? Also, is there a way to set the EOIMode before calling visadev? Because it seems like the only way this works now is that you call visadev to connect to the device, it errors out because it needs EOIMode off first and it did not understand what *IDN? command was. At this point you would have to clear the error on the instrument caused by sending an unknown command each time a connection was made. It appears that the Visadev function performs a *IDN? when trying to open the connection to a GPIB instrument. This allows it to populate the the information such as model, etc. The issue is that some instruments do not support *IDN? and of those instruments there are some that need the EOIMode set to off in order to function correctly.
So is there a way to suppress sending the *IDN? when using the visadev or is there a way to specify the identity command it is using? Also, is there a way to set the EOIMode before calling visadev? Because it seems like the only way this works now is that you call visadev to connect to the device, it errors out because it needs EOIMode off first and it did not understand what *IDN? command was. At this point you would have to clear the error on the instrument caused by sending an unknown command each time a connection was made. visadev, eoimode, idn?, *idn?, identify, visa, handles MATLAB Answers — New Questions
password field is not taking input
In my ubuntu 22.04 I was installing matlab R2023a , during the process after filling email id the password field is not rasponding( not taking input)In my ubuntu 22.04 I was installing matlab R2023a , during the process after filling email id the password field is not rasponding( not taking input) In my ubuntu 22.04 I was installing matlab R2023a , during the process after filling email id the password field is not rasponding( not taking input) password filed is not taking input MATLAB Answers — New Questions
How do I install MATLAB and its toolboxes?
I would like to install MATLAB and/or its toolboxes on my internet-connected computer. How can I do this?I would like to install MATLAB and/or its toolboxes on my internet-connected computer. How can I do this? I would like to install MATLAB and/or its toolboxes on my internet-connected computer. How can I do this? MATLAB Answers — New Questions
Detect quantum wire dots (appear as circles) and isolate them from noisy background binarized
Hey All
I am working on a project involving photos from a live feed of quantum wire dots and I was wondering what might be the best approach for isolating the circles and the excited laser properly. My current code can sometimes lead to mistakes and non-circular formations. Any help would be much appreciated. I have shared my current code as well as an image comparison below!
I = "QD.jpg"
%loads image from a file into an array
Img = imread(I);
%grayscales image for easier analysis
ImgGray = im2gray(Img);
%makes a clear contrast between foreground and background
adjustedImg = imadjust(ImgGray);
%binarizing image into 0(black) and 1(white)
BwImg = imbinarize(adjustedImg, ‘adaptive’, ‘ForegroundPolarity’, ‘dark’, ‘Sensitivity’, 0.4);
%inverting it so that foreground appears as white and background as black
invertedBwImg = ~BwImg;
%morpholigically changing the image by opening and closing, in this case removing small white
%objects from black background and removing the remaining black spots from
%the white patches
se = strel("disk",15);
openedImg = imopen(invertedBwImg,se);
closedImg = imclose(openedImg,se);
% Apply a threshold to keep only pixels above the threshold value
thresholdedImg = ImgGray > 120;
% Multiply the original grayscale image by the threshold mask to keep pixel values
excitedimg = uint8(thresholdedImg) .* ImgGray;
% Label connected components
labeledImg = bwlabel(closedImg);
% Measure properties of image regions
stats = regionprops(labeledImg, ‘Eccentricity’);
% Define an eccentricity threshold
eccentricityThreshold = 0.76;
% Initialize a mask for the filtered image
filteredImg = ismember(labeledImg, find([stats.Eccentricity] < eccentricityThreshold));
% Convert logical image(filterImg) to uint8 image in order to comebine with
% excitedimage
uint8Img = uint8(filteredImg) * 255;
%final image with excited light and quantum wires
finalImg = uint8Img + excitedimg;
% Create a new figure for displaying images
figure;
% Display the original image
subplot(1, 2, 1);
imshow(Img);
title(‘Original Image’);
% Display the filtered binary image
subplot(1, 2, 2);
imshow(finalImg);
title(‘Updated Result’);
% Return the figure handle as the result
result = gcf;Hey All
I am working on a project involving photos from a live feed of quantum wire dots and I was wondering what might be the best approach for isolating the circles and the excited laser properly. My current code can sometimes lead to mistakes and non-circular formations. Any help would be much appreciated. I have shared my current code as well as an image comparison below!
I = "QD.jpg"
%loads image from a file into an array
Img = imread(I);
%grayscales image for easier analysis
ImgGray = im2gray(Img);
%makes a clear contrast between foreground and background
adjustedImg = imadjust(ImgGray);
%binarizing image into 0(black) and 1(white)
BwImg = imbinarize(adjustedImg, ‘adaptive’, ‘ForegroundPolarity’, ‘dark’, ‘Sensitivity’, 0.4);
%inverting it so that foreground appears as white and background as black
invertedBwImg = ~BwImg;
%morpholigically changing the image by opening and closing, in this case removing small white
%objects from black background and removing the remaining black spots from
%the white patches
se = strel("disk",15);
openedImg = imopen(invertedBwImg,se);
closedImg = imclose(openedImg,se);
% Apply a threshold to keep only pixels above the threshold value
thresholdedImg = ImgGray > 120;
% Multiply the original grayscale image by the threshold mask to keep pixel values
excitedimg = uint8(thresholdedImg) .* ImgGray;
% Label connected components
labeledImg = bwlabel(closedImg);
% Measure properties of image regions
stats = regionprops(labeledImg, ‘Eccentricity’);
% Define an eccentricity threshold
eccentricityThreshold = 0.76;
% Initialize a mask for the filtered image
filteredImg = ismember(labeledImg, find([stats.Eccentricity] < eccentricityThreshold));
% Convert logical image(filterImg) to uint8 image in order to comebine with
% excitedimage
uint8Img = uint8(filteredImg) * 255;
%final image with excited light and quantum wires
finalImg = uint8Img + excitedimg;
% Create a new figure for displaying images
figure;
% Display the original image
subplot(1, 2, 1);
imshow(Img);
title(‘Original Image’);
% Display the filtered binary image
subplot(1, 2, 2);
imshow(finalImg);
title(‘Updated Result’);
% Return the figure handle as the result
result = gcf; Hey All
I am working on a project involving photos from a live feed of quantum wire dots and I was wondering what might be the best approach for isolating the circles and the excited laser properly. My current code can sometimes lead to mistakes and non-circular formations. Any help would be much appreciated. I have shared my current code as well as an image comparison below!
I = "QD.jpg"
%loads image from a file into an array
Img = imread(I);
%grayscales image for easier analysis
ImgGray = im2gray(Img);
%makes a clear contrast between foreground and background
adjustedImg = imadjust(ImgGray);
%binarizing image into 0(black) and 1(white)
BwImg = imbinarize(adjustedImg, ‘adaptive’, ‘ForegroundPolarity’, ‘dark’, ‘Sensitivity’, 0.4);
%inverting it so that foreground appears as white and background as black
invertedBwImg = ~BwImg;
%morpholigically changing the image by opening and closing, in this case removing small white
%objects from black background and removing the remaining black spots from
%the white patches
se = strel("disk",15);
openedImg = imopen(invertedBwImg,se);
closedImg = imclose(openedImg,se);
% Apply a threshold to keep only pixels above the threshold value
thresholdedImg = ImgGray > 120;
% Multiply the original grayscale image by the threshold mask to keep pixel values
excitedimg = uint8(thresholdedImg) .* ImgGray;
% Label connected components
labeledImg = bwlabel(closedImg);
% Measure properties of image regions
stats = regionprops(labeledImg, ‘Eccentricity’);
% Define an eccentricity threshold
eccentricityThreshold = 0.76;
% Initialize a mask for the filtered image
filteredImg = ismember(labeledImg, find([stats.Eccentricity] < eccentricityThreshold));
% Convert logical image(filterImg) to uint8 image in order to comebine with
% excitedimage
uint8Img = uint8(filteredImg) * 255;
%final image with excited light and quantum wires
finalImg = uint8Img + excitedimg;
% Create a new figure for displaying images
figure;
% Display the original image
subplot(1, 2, 1);
imshow(Img);
title(‘Original Image’);
% Display the filtered binary image
subplot(1, 2, 2);
imshow(finalImg);
title(‘Updated Result’);
% Return the figure handle as the result
result = gcf; image processing, image segmentation, quantum dot MATLAB Answers — New Questions
i have a vector in lenght 5, i need to check if a sum of 2 or more elements in the vector is equal to another element at the same vector how to do that?
i have a vector in lenght 5, i need to check if a sum of 2 or more elements in the vector is equal to another element at the same vector how to do that?
i try to do a loop inside a loop but it doesnt works
if someone has an idea it would be helpful.
thank youi have a vector in lenght 5, i need to check if a sum of 2 or more elements in the vector is equal to another element at the same vector how to do that?
i try to do a loop inside a loop but it doesnt works
if someone has an idea it would be helpful.
thank you i have a vector in lenght 5, i need to check if a sum of 2 or more elements in the vector is equal to another element at the same vector how to do that?
i try to do a loop inside a loop but it doesnt works
if someone has an idea it would be helpful.
thank you vector, loop, for loop, if MATLAB Answers — New Questions
Truth Table Test Coverage Results Unclear
I have tested a 3-input truth table with all permutations of inputs (000 001 010 100 011 110 101 111) and not received condition coverage. It is unclear to me what the red letters mean in my coverage report. I have looked at this link and haven’t gotten much clarity. https://www.mathworks.com/help/slcoverage/ug/coverage-for-truth-tables.html
Here are the table results below. What is the meaning of the red letters in parenthesis? For action 2, it says (ok), meaning I clearly tested TTF, but, then it gives a red T in that column.
Thank you,
CodyI have tested a 3-input truth table with all permutations of inputs (000 001 010 100 011 110 101 111) and not received condition coverage. It is unclear to me what the red letters mean in my coverage report. I have looked at this link and haven’t gotten much clarity. https://www.mathworks.com/help/slcoverage/ug/coverage-for-truth-tables.html
Here are the table results below. What is the meaning of the red letters in parenthesis? For action 2, it says (ok), meaning I clearly tested TTF, but, then it gives a red T in that column.
Thank you,
Cody I have tested a 3-input truth table with all permutations of inputs (000 001 010 100 011 110 101 111) and not received condition coverage. It is unclear to me what the red letters mean in my coverage report. I have looked at this link and haven’t gotten much clarity. https://www.mathworks.com/help/slcoverage/ug/coverage-for-truth-tables.html
Here are the table results below. What is the meaning of the red letters in parenthesis? For action 2, it says (ok), meaning I clearly tested TTF, but, then it gives a red T in that column.
Thank you,
Cody test coverage, coverage, unit test, test manager, truth table, simulink MATLAB Answers — New Questions
How to make a symmetric matrix from a muxed signal in MATLAB fcn block?
Hello,
I am developping a system that utilizes an MNA in simulink and need to use the fcn Block in order to calculate de correct PV tension.
I have 60 converters that are connected on a DC bus in a symmetrical format and manage to make the MNA work for a single side, but as soon as I use the variable I wrote the length of the muxed signal in for different points it gives me an error.
Here is the code I made:
function [UPV, Ibus]= fcn(IPV, Ubus)
R1 = 0.00748 / 2;
R = 0.00748;
n = length(IPV); %Logging the number of input in the muxed signal
d = floor(n/2); %Finding the end of the first side
e = d+1; %Start of the second side
G = diag(2/R * ones(n, 1)) + diag(-1/R * ones(n-1, 1), 1) + diag(-1/R * ones(n-1, 1), -1); %Making the impedance matrix.
G(1, 1) = 1/R; %Correction of the first resistor
G(d,d) = 1/R; %Correction of the resistor near the injection point on one side
G(e,d) = 0; %Removing resistor from injection point
G(d,e) = 0; %Removing resistor from injection point
G(e,e) = 1/R; %Correction of the resistor near the injection on the second side
G(n, n) = 1/R; %Correction of the last resistor
B = zeros(n, 1);
B(d) = 1;
B(e) = 1;
A = R1;
MNAG = [G -B; B’ A]; %MNA matrix
sources = [IPV(:); Ubus];
resultats = MNAG sources;
UPV = resultats(1:n);
Ibus = 2*resultats(n+1);
In the various iterrations of this code I managed to make the programm run but all output became NaN.Hello,
I am developping a system that utilizes an MNA in simulink and need to use the fcn Block in order to calculate de correct PV tension.
I have 60 converters that are connected on a DC bus in a symmetrical format and manage to make the MNA work for a single side, but as soon as I use the variable I wrote the length of the muxed signal in for different points it gives me an error.
Here is the code I made:
function [UPV, Ibus]= fcn(IPV, Ubus)
R1 = 0.00748 / 2;
R = 0.00748;
n = length(IPV); %Logging the number of input in the muxed signal
d = floor(n/2); %Finding the end of the first side
e = d+1; %Start of the second side
G = diag(2/R * ones(n, 1)) + diag(-1/R * ones(n-1, 1), 1) + diag(-1/R * ones(n-1, 1), -1); %Making the impedance matrix.
G(1, 1) = 1/R; %Correction of the first resistor
G(d,d) = 1/R; %Correction of the resistor near the injection point on one side
G(e,d) = 0; %Removing resistor from injection point
G(d,e) = 0; %Removing resistor from injection point
G(e,e) = 1/R; %Correction of the resistor near the injection on the second side
G(n, n) = 1/R; %Correction of the last resistor
B = zeros(n, 1);
B(d) = 1;
B(e) = 1;
A = R1;
MNAG = [G -B; B’ A]; %MNA matrix
sources = [IPV(:); Ubus];
resultats = MNAG sources;
UPV = resultats(1:n);
Ibus = 2*resultats(n+1);
In the various iterrations of this code I managed to make the programm run but all output became NaN. Hello,
I am developping a system that utilizes an MNA in simulink and need to use the fcn Block in order to calculate de correct PV tension.
I have 60 converters that are connected on a DC bus in a symmetrical format and manage to make the MNA work for a single side, but as soon as I use the variable I wrote the length of the muxed signal in for different points it gives me an error.
Here is the code I made:
function [UPV, Ibus]= fcn(IPV, Ubus)
R1 = 0.00748 / 2;
R = 0.00748;
n = length(IPV); %Logging the number of input in the muxed signal
d = floor(n/2); %Finding the end of the first side
e = d+1; %Start of the second side
G = diag(2/R * ones(n, 1)) + diag(-1/R * ones(n-1, 1), 1) + diag(-1/R * ones(n-1, 1), -1); %Making the impedance matrix.
G(1, 1) = 1/R; %Correction of the first resistor
G(d,d) = 1/R; %Correction of the resistor near the injection point on one side
G(e,d) = 0; %Removing resistor from injection point
G(d,e) = 0; %Removing resistor from injection point
G(e,e) = 1/R; %Correction of the resistor near the injection on the second side
G(n, n) = 1/R; %Correction of the last resistor
B = zeros(n, 1);
B(d) = 1;
B(e) = 1;
A = R1;
MNAG = [G -B; B’ A]; %MNA matrix
sources = [IPV(:); Ubus];
resultats = MNAG sources;
UPV = resultats(1:n);
Ibus = 2*resultats(n+1);
In the various iterrations of this code I managed to make the programm run but all output became NaN. mna, symmetric matrix, muxed signal MATLAB Answers — New Questions
Legend colors change when I have two y axes
Hi,
I am having difficulties with making figure. Here is the thing:
I have 10 different data sets. 2nd starts at the timestamp 1st end etc. Each data sets are saved and have similarly named variablses. I want data "density" to be on the left y axis and 7 measurements to be on the right y axis. The problem is with legend. After 1st measurement everything is ok. But when I run code again with another dataset, legend colors and linestyle will change. I’ll add both code and pictures of legends in several times.
Legend after 1st measurement. This is how it should look like:
And after 2 runs:
after many runs:
The program is using whole different legends.
So, here is the code. (before I had 8 measurements, but now I only need 7)
colors=["#028A0F","#1D57A9","#3DCBC8","#9C58A1","#F0D04D","#CD0027","#EF9F26","#B2B3B5","#FA9DAC","#98FF98","#67032F","#010101"];
fig1=figure(1);
hold on
yyaxis left
plot(Time_h,density, ‘color’, ‘#000000′,’LineStyle’,’:’);
axLeft=gca;
axLeft.YColor = "#000000";
axLeft.XLim=[0,350];
axLeft.YLim=[0,1.5];
ylabel(‘density’);
yyaxis right
plot(Time_h,Measure_1, ‘color’, colors(1),’LineStyle’,’-‘,’Marker’,’none’);
plot(Time_h,Measure_2, ‘color’, colors(2),’LineStyle’,’-‘,’Marker’,’none’);
plot(Time_h,Measure_3, ‘color’, colors(3),’LineStyle’,’-‘,’Marker’,’none’);
plot(Time_h,Measure_4, ‘color’, colors(4),’LineStyle’,’-‘,’Marker’,’none’);
plot(Time_h,Measure_5, ‘color’, colors(5),’LineStyle’,’-‘,’Marker’,’none’);
plot(Time_h,Measure_6, ‘color’, colors(6),’LineStyle’,’-‘,’Marker’,’none’);
plot(Time_h,Measure_7, ‘color’, colors(7),’LineStyle’,’-‘,’Marker’,’none’);
ylabel(”)
axRight=gca;
axRight.YLim=[0,1];
axRight.YColor = "#000000";
lgnd=legend(‘density’,’Measurement 1′,’Measurement 2′,’Measurement 3′,’Measurement 4′,’Measurement 5′,’Measurement 6′,’Measurement 7′);
xlabel(‘Time_ (h)’);
I upload always the data and then run the code and then repeat. I don’t close the picture between these. The final picture is then saved.
So thanks in advance and I can describe problem more if nessessary.Hi,
I am having difficulties with making figure. Here is the thing:
I have 10 different data sets. 2nd starts at the timestamp 1st end etc. Each data sets are saved and have similarly named variablses. I want data "density" to be on the left y axis and 7 measurements to be on the right y axis. The problem is with legend. After 1st measurement everything is ok. But when I run code again with another dataset, legend colors and linestyle will change. I’ll add both code and pictures of legends in several times.
Legend after 1st measurement. This is how it should look like:
And after 2 runs:
after many runs:
The program is using whole different legends.
So, here is the code. (before I had 8 measurements, but now I only need 7)
colors=["#028A0F","#1D57A9","#3DCBC8","#9C58A1","#F0D04D","#CD0027","#EF9F26","#B2B3B5","#FA9DAC","#98FF98","#67032F","#010101"];
fig1=figure(1);
hold on
yyaxis left
plot(Time_h,density, ‘color’, ‘#000000′,’LineStyle’,’:’);
axLeft=gca;
axLeft.YColor = "#000000";
axLeft.XLim=[0,350];
axLeft.YLim=[0,1.5];
ylabel(‘density’);
yyaxis right
plot(Time_h,Measure_1, ‘color’, colors(1),’LineStyle’,’-‘,’Marker’,’none’);
plot(Time_h,Measure_2, ‘color’, colors(2),’LineStyle’,’-‘,’Marker’,’none’);
plot(Time_h,Measure_3, ‘color’, colors(3),’LineStyle’,’-‘,’Marker’,’none’);
plot(Time_h,Measure_4, ‘color’, colors(4),’LineStyle’,’-‘,’Marker’,’none’);
plot(Time_h,Measure_5, ‘color’, colors(5),’LineStyle’,’-‘,’Marker’,’none’);
plot(Time_h,Measure_6, ‘color’, colors(6),’LineStyle’,’-‘,’Marker’,’none’);
plot(Time_h,Measure_7, ‘color’, colors(7),’LineStyle’,’-‘,’Marker’,’none’);
ylabel(”)
axRight=gca;
axRight.YLim=[0,1];
axRight.YColor = "#000000";
lgnd=legend(‘density’,’Measurement 1′,’Measurement 2′,’Measurement 3′,’Measurement 4′,’Measurement 5′,’Measurement 6′,’Measurement 7′);
xlabel(‘Time_ (h)’);
I upload always the data and then run the code and then repeat. I don’t close the picture between these. The final picture is then saved.
So thanks in advance and I can describe problem more if nessessary. Hi,
I am having difficulties with making figure. Here is the thing:
I have 10 different data sets. 2nd starts at the timestamp 1st end etc. Each data sets are saved and have similarly named variablses. I want data "density" to be on the left y axis and 7 measurements to be on the right y axis. The problem is with legend. After 1st measurement everything is ok. But when I run code again with another dataset, legend colors and linestyle will change. I’ll add both code and pictures of legends in several times.
Legend after 1st measurement. This is how it should look like:
And after 2 runs:
after many runs:
The program is using whole different legends.
So, here is the code. (before I had 8 measurements, but now I only need 7)
colors=["#028A0F","#1D57A9","#3DCBC8","#9C58A1","#F0D04D","#CD0027","#EF9F26","#B2B3B5","#FA9DAC","#98FF98","#67032F","#010101"];
fig1=figure(1);
hold on
yyaxis left
plot(Time_h,density, ‘color’, ‘#000000′,’LineStyle’,’:’);
axLeft=gca;
axLeft.YColor = "#000000";
axLeft.XLim=[0,350];
axLeft.YLim=[0,1.5];
ylabel(‘density’);
yyaxis right
plot(Time_h,Measure_1, ‘color’, colors(1),’LineStyle’,’-‘,’Marker’,’none’);
plot(Time_h,Measure_2, ‘color’, colors(2),’LineStyle’,’-‘,’Marker’,’none’);
plot(Time_h,Measure_3, ‘color’, colors(3),’LineStyle’,’-‘,’Marker’,’none’);
plot(Time_h,Measure_4, ‘color’, colors(4),’LineStyle’,’-‘,’Marker’,’none’);
plot(Time_h,Measure_5, ‘color’, colors(5),’LineStyle’,’-‘,’Marker’,’none’);
plot(Time_h,Measure_6, ‘color’, colors(6),’LineStyle’,’-‘,’Marker’,’none’);
plot(Time_h,Measure_7, ‘color’, colors(7),’LineStyle’,’-‘,’Marker’,’none’);
ylabel(”)
axRight=gca;
axRight.YLim=[0,1];
axRight.YColor = "#000000";
lgnd=legend(‘density’,’Measurement 1′,’Measurement 2′,’Measurement 3′,’Measurement 4′,’Measurement 5′,’Measurement 6′,’Measurement 7′);
xlabel(‘Time_ (h)’);
I upload always the data and then run the code and then repeat. I don’t close the picture between these. The final picture is then saved.
So thanks in advance and I can describe problem more if nessessary. legend, yyaxis, colors, colororder MATLAB Answers — New Questions
saving elements of a dataset as images
hello i would like to ask how to save inputData(:,:,idxSelected(i)) as an image file. thanks very much.
function [data,labelsVec,timestamps] = loadCSIDataset(fileName,label,visualizeData)
% loadCSIDataset Loads and visualizes the pre-recorded CSI dataset
% [DATA,LABELSVEC,TIMESTAMPS] =
% loadCSIDataset(FILENAME,LABEL,VISUALIZEDATA) loads the dataset that
% contains the data with the label (LABEL). Pre-recorded CSIs are
% visualized if (VISUALIZEDATA) is true. The function returns the
% pre-recorded beacon frame CSI (DATA), related timestamps (TIMESTAMPS),
% and the categorical labels vector (LABELSVEC).
% Copyright 2022-2024 The MathWorks, Inc.
arguments
fileName {char,string}
label (1,1) string
visualizeData = true;
end
% Load the pre-recorded dataset
datasetDir = which(fileName);
loadedData = load(datasetDir);
data = loadedData.data;
labelsVec = categorical(repmat(label,size(data,ndims(data)),1));
timestamps = loadedData.timestamps;
disp([‘Dimensions of the ‘ char(label) ‘ dataset (numSubcarriers x numPackets x numCaptures): ‘ ‘[‘ num2str(size(data)) ‘]’])
% Visualize the dataset
if visualizeData
plotSamplesFromDataset(data,label);
end
% Plot samples from the pre-recorded dataset
function plotSamplesFromDataset(data,mode)
% Plot at most three random samples of the dataset
inputData = abs(data); % Visualize only the magnitude of the CSI
numTotalCaptures = size(inputData,ndims(inputData));
numPlots = min(3,numTotalCaptures);
idxSelected = sort(randperm(numTotalCaptures,numPlots));
figure;
T = tiledlayout(2,numPlots,’TileSpacing’,’compact’);
% Plot 1 – CSI image
for i = 1:numPlots
nexttile
imagesc(inputData(:,:,idxSelected(i)));
colorbar;
xlabel(‘Packets’);
ylabel(‘Subcarriers’);
title([‘Raw CSI (#’ num2str(idxSelected(i)),’)’]);
end
% Plot 2 – Normalized CSI periodogram
for j = 1:numPlots
nexttile
imagesc(csi2periodogram(inputData(:,:,idxSelected(j))));
colorbar;
clim([0 1]);
xlabel(‘Temporal Index’);
ylabel(‘Spatial Index’);
title([‘CSI Periodogram (#’ num2str(idxSelected(j)),’)’]);
title(T,[‘Randomly Selected Samples of "’, char(mode) ‘" Data’]);
set(gcf,’Position’,[0 0 650 450]);
end
end
endhello i would like to ask how to save inputData(:,:,idxSelected(i)) as an image file. thanks very much.
function [data,labelsVec,timestamps] = loadCSIDataset(fileName,label,visualizeData)
% loadCSIDataset Loads and visualizes the pre-recorded CSI dataset
% [DATA,LABELSVEC,TIMESTAMPS] =
% loadCSIDataset(FILENAME,LABEL,VISUALIZEDATA) loads the dataset that
% contains the data with the label (LABEL). Pre-recorded CSIs are
% visualized if (VISUALIZEDATA) is true. The function returns the
% pre-recorded beacon frame CSI (DATA), related timestamps (TIMESTAMPS),
% and the categorical labels vector (LABELSVEC).
% Copyright 2022-2024 The MathWorks, Inc.
arguments
fileName {char,string}
label (1,1) string
visualizeData = true;
end
% Load the pre-recorded dataset
datasetDir = which(fileName);
loadedData = load(datasetDir);
data = loadedData.data;
labelsVec = categorical(repmat(label,size(data,ndims(data)),1));
timestamps = loadedData.timestamps;
disp([‘Dimensions of the ‘ char(label) ‘ dataset (numSubcarriers x numPackets x numCaptures): ‘ ‘[‘ num2str(size(data)) ‘]’])
% Visualize the dataset
if visualizeData
plotSamplesFromDataset(data,label);
end
% Plot samples from the pre-recorded dataset
function plotSamplesFromDataset(data,mode)
% Plot at most three random samples of the dataset
inputData = abs(data); % Visualize only the magnitude of the CSI
numTotalCaptures = size(inputData,ndims(inputData));
numPlots = min(3,numTotalCaptures);
idxSelected = sort(randperm(numTotalCaptures,numPlots));
figure;
T = tiledlayout(2,numPlots,’TileSpacing’,’compact’);
% Plot 1 – CSI image
for i = 1:numPlots
nexttile
imagesc(inputData(:,:,idxSelected(i)));
colorbar;
xlabel(‘Packets’);
ylabel(‘Subcarriers’);
title([‘Raw CSI (#’ num2str(idxSelected(i)),’)’]);
end
% Plot 2 – Normalized CSI periodogram
for j = 1:numPlots
nexttile
imagesc(csi2periodogram(inputData(:,:,idxSelected(j))));
colorbar;
clim([0 1]);
xlabel(‘Temporal Index’);
ylabel(‘Spatial Index’);
title([‘CSI Periodogram (#’ num2str(idxSelected(j)),’)’]);
title(T,[‘Randomly Selected Samples of "’, char(mode) ‘" Data’]);
set(gcf,’Position’,[0 0 650 450]);
end
end
end hello i would like to ask how to save inputData(:,:,idxSelected(i)) as an image file. thanks very much.
function [data,labelsVec,timestamps] = loadCSIDataset(fileName,label,visualizeData)
% loadCSIDataset Loads and visualizes the pre-recorded CSI dataset
% [DATA,LABELSVEC,TIMESTAMPS] =
% loadCSIDataset(FILENAME,LABEL,VISUALIZEDATA) loads the dataset that
% contains the data with the label (LABEL). Pre-recorded CSIs are
% visualized if (VISUALIZEDATA) is true. The function returns the
% pre-recorded beacon frame CSI (DATA), related timestamps (TIMESTAMPS),
% and the categorical labels vector (LABELSVEC).
% Copyright 2022-2024 The MathWorks, Inc.
arguments
fileName {char,string}
label (1,1) string
visualizeData = true;
end
% Load the pre-recorded dataset
datasetDir = which(fileName);
loadedData = load(datasetDir);
data = loadedData.data;
labelsVec = categorical(repmat(label,size(data,ndims(data)),1));
timestamps = loadedData.timestamps;
disp([‘Dimensions of the ‘ char(label) ‘ dataset (numSubcarriers x numPackets x numCaptures): ‘ ‘[‘ num2str(size(data)) ‘]’])
% Visualize the dataset
if visualizeData
plotSamplesFromDataset(data,label);
end
% Plot samples from the pre-recorded dataset
function plotSamplesFromDataset(data,mode)
% Plot at most three random samples of the dataset
inputData = abs(data); % Visualize only the magnitude of the CSI
numTotalCaptures = size(inputData,ndims(inputData));
numPlots = min(3,numTotalCaptures);
idxSelected = sort(randperm(numTotalCaptures,numPlots));
figure;
T = tiledlayout(2,numPlots,’TileSpacing’,’compact’);
% Plot 1 – CSI image
for i = 1:numPlots
nexttile
imagesc(inputData(:,:,idxSelected(i)));
colorbar;
xlabel(‘Packets’);
ylabel(‘Subcarriers’);
title([‘Raw CSI (#’ num2str(idxSelected(i)),’)’]);
end
% Plot 2 – Normalized CSI periodogram
for j = 1:numPlots
nexttile
imagesc(csi2periodogram(inputData(:,:,idxSelected(j))));
colorbar;
clim([0 1]);
xlabel(‘Temporal Index’);
ylabel(‘Spatial Index’);
title([‘CSI Periodogram (#’ num2str(idxSelected(j)),’)’]);
title(T,[‘Randomly Selected Samples of "’, char(mode) ‘" Data’]);
set(gcf,’Position’,[0 0 650 450]);
end
end
end datasets, elements, images MATLAB Answers — New Questions
mclInitializeApplication sometimes will hangs forever
Calling mclInitializeApplication will hang,
it will not return 0 or 1.. just hangs in there.
Sometimes it will hang forever,
Sometimes hang for few minutes and that return success.
Sometimes works correctly and return success immediately.
So I suspect it’s a ‘system’ error, while other users also running matlab on the same servers
I’m using matlab as ‘C Shared Library Integration’,
included at my project via DPI-C, with Xcelium simulator (used for Hardware RTL simulation)
Runing at Unix servers.
from the documentation it says:
" mclInitializeApplication must be called once only per process."
I’m running the my program which is Xcelium simulator, which for every run should be ‘single’ process.
it will be allocated to a server on the grid, and run there. so from my point of view it’s a new and fresh instance of the program, and I can’t see how it’s cross contaminating other job that is already running.
Thanks !Calling mclInitializeApplication will hang,
it will not return 0 or 1.. just hangs in there.
Sometimes it will hang forever,
Sometimes hang for few minutes and that return success.
Sometimes works correctly and return success immediately.
So I suspect it’s a ‘system’ error, while other users also running matlab on the same servers
I’m using matlab as ‘C Shared Library Integration’,
included at my project via DPI-C, with Xcelium simulator (used for Hardware RTL simulation)
Runing at Unix servers.
from the documentation it says:
" mclInitializeApplication must be called once only per process."
I’m running the my program which is Xcelium simulator, which for every run should be ‘single’ process.
it will be allocated to a server on the grid, and run there. so from my point of view it’s a new and fresh instance of the program, and I can’t see how it’s cross contaminating other job that is already running.
Thanks ! Calling mclInitializeApplication will hang,
it will not return 0 or 1.. just hangs in there.
Sometimes it will hang forever,
Sometimes hang for few minutes and that return success.
Sometimes works correctly and return success immediately.
So I suspect it’s a ‘system’ error, while other users also running matlab on the same servers
I’m using matlab as ‘C Shared Library Integration’,
included at my project via DPI-C, with Xcelium simulator (used for Hardware RTL simulation)
Runing at Unix servers.
from the documentation it says:
" mclInitializeApplication must be called once only per process."
I’m running the my program which is Xcelium simulator, which for every run should be ‘single’ process.
it will be allocated to a server on the grid, and run there. so from my point of view it’s a new and fresh instance of the program, and I can’t see how it’s cross contaminating other job that is already running.
Thanks ! mclinitializeapplication hangs MATLAB Answers — New Questions
Is it possible to use Simulink’s DDS BlockSet to communicate between two Simulink models on two computers?
the giving examples only use dds blockset to connect things in the same simulink model, can I use dds blockset to do more, such as using it to send and receive data between 2 seperate simulink models (.slx)? even when the 2 models are set on 2 computers?
If it is possibel, what can I do to set the dds blockset?the giving examples only use dds blockset to connect things in the same simulink model, can I use dds blockset to do more, such as using it to send and receive data between 2 seperate simulink models (.slx)? even when the 2 models are set on 2 computers?
If it is possibel, what can I do to set the dds blockset? the giving examples only use dds blockset to connect things in the same simulink model, can I use dds blockset to do more, such as using it to send and receive data between 2 seperate simulink models (.slx)? even when the 2 models are set on 2 computers?
If it is possibel, what can I do to set the dds blockset? dds, dds blockset, communication between different models MATLAB Answers — New Questions
Arrays have incompatible sizes for this operation error while checking dropdown.value not equal to a char value
I have created an app in appdesigner and it has a dropdown. And I check the value of this dropdown to a string value.
function SelectBatteryDropDownValueChanged(app, event)
if app.SelectBatteryDropDown.Value ~= ‘none’
end
end
‘none’ is one of the values initialised to the dropdown. Now a select a value from the dropdown I expect the program to check first if the value is not equal to ‘none’ and if true execute some code. But It is giving an error :
Arrays have incompatible sizes for this operation.
This doesnt make any sense since both ‘none’ and app.SelectBatteryDropDown.Value are of type char, I checked to make sure. Yet this error is coming. Why is that? How can I fix this. Thank you.I have created an app in appdesigner and it has a dropdown. And I check the value of this dropdown to a string value.
function SelectBatteryDropDownValueChanged(app, event)
if app.SelectBatteryDropDown.Value ~= ‘none’
end
end
‘none’ is one of the values initialised to the dropdown. Now a select a value from the dropdown I expect the program to check first if the value is not equal to ‘none’ and if true execute some code. But It is giving an error :
Arrays have incompatible sizes for this operation.
This doesnt make any sense since both ‘none’ and app.SelectBatteryDropDown.Value are of type char, I checked to make sure. Yet this error is coming. Why is that? How can I fix this. Thank you. I have created an app in appdesigner and it has a dropdown. And I check the value of this dropdown to a string value.
function SelectBatteryDropDownValueChanged(app, event)
if app.SelectBatteryDropDown.Value ~= ‘none’
end
end
‘none’ is one of the values initialised to the dropdown. Now a select a value from the dropdown I expect the program to check first if the value is not equal to ‘none’ and if true execute some code. But It is giving an error :
Arrays have incompatible sizes for this operation.
This doesnt make any sense since both ‘none’ and app.SelectBatteryDropDown.Value are of type char, I checked to make sure. Yet this error is coming. Why is that? How can I fix this. Thank you. matlab, appdesigner MATLAB Answers — New Questions
How can I plot a matrix using pcolor and colorscale as log?
I have a timeseries matrix data of a lidar. I want to plot the time series keeping colorbar as logscale.
I have written the following code but it shows an error
load time_June.mat
load elevation_June_5km.mat
load backscatter_June_5km.mat
load raw_backscatter_June_5km.mat
figure(1);
pcolor(time_June, elevation_June_5km, backscatter_June_5km); shading interp
c = colorbar;
caxis([10^-7 10^-4]);
set(gca, ‘ColorScale’, ‘log’);
c.Label.String = ‘Attenuated backscatter coefficient (m^{-1} sr^{-1})’;
c.Ruler.Scale = ‘log’;
c.Ruler.MinorTick = ‘on’;
colormap jet;
set(gca, ‘YDir’, ‘normal’);
xlabel(‘Time (LT)’);
ylabel(‘Altitude (km)’);
axis tight;
set(gca, ‘FontName’, ‘Times’, ‘FontSize’, 14);
startDate = datetime(2023, 6, 16);
endDate = datetime(2023, 6, 25);
xlim([startDate, endDate]);
Error:
Warning: Error creating or updating Surface
Error in value of property CData
DataSpace or ColorSpace transform method failed.I have a timeseries matrix data of a lidar. I want to plot the time series keeping colorbar as logscale.
I have written the following code but it shows an error
load time_June.mat
load elevation_June_5km.mat
load backscatter_June_5km.mat
load raw_backscatter_June_5km.mat
figure(1);
pcolor(time_June, elevation_June_5km, backscatter_June_5km); shading interp
c = colorbar;
caxis([10^-7 10^-4]);
set(gca, ‘ColorScale’, ‘log’);
c.Label.String = ‘Attenuated backscatter coefficient (m^{-1} sr^{-1})’;
c.Ruler.Scale = ‘log’;
c.Ruler.MinorTick = ‘on’;
colormap jet;
set(gca, ‘YDir’, ‘normal’);
xlabel(‘Time (LT)’);
ylabel(‘Altitude (km)’);
axis tight;
set(gca, ‘FontName’, ‘Times’, ‘FontSize’, 14);
startDate = datetime(2023, 6, 16);
endDate = datetime(2023, 6, 25);
xlim([startDate, endDate]);
Error:
Warning: Error creating or updating Surface
Error in value of property CData
DataSpace or ColorSpace transform method failed. I have a timeseries matrix data of a lidar. I want to plot the time series keeping colorbar as logscale.
I have written the following code but it shows an error
load time_June.mat
load elevation_June_5km.mat
load backscatter_June_5km.mat
load raw_backscatter_June_5km.mat
figure(1);
pcolor(time_June, elevation_June_5km, backscatter_June_5km); shading interp
c = colorbar;
caxis([10^-7 10^-4]);
set(gca, ‘ColorScale’, ‘log’);
c.Label.String = ‘Attenuated backscatter coefficient (m^{-1} sr^{-1})’;
c.Ruler.Scale = ‘log’;
c.Ruler.MinorTick = ‘on’;
colormap jet;
set(gca, ‘YDir’, ‘normal’);
xlabel(‘Time (LT)’);
ylabel(‘Altitude (km)’);
axis tight;
set(gca, ‘FontName’, ‘Times’, ‘FontSize’, 14);
startDate = datetime(2023, 6, 16);
endDate = datetime(2023, 6, 25);
xlim([startDate, endDate]);
Error:
Warning: Error creating or updating Surface
Error in value of property CData
DataSpace or ColorSpace transform method failed. pcolor, logscale, colorbar, matrix MATLAB Answers — New Questions
command for Importing a file in systemdesk
How to import a file in Dspace using m script?How to import a file in Dspace using m script? How to import a file in Dspace using m script? dspace using mscript MATLAB Answers — New Questions
KernelScale optimization for ARD kernels
Hello,
How are KernelScales determined for ARD kernels since we cannot choose to optimize these kernels?
Constant initial KernelParameters specified by the user are not the same once the metamodel is created using fitrgp.
So there is something happening leading to a change in kernel scales (but not specified in the documentation)..Hello,
How are KernelScales determined for ARD kernels since we cannot choose to optimize these kernels?
Constant initial KernelParameters specified by the user are not the same once the metamodel is created using fitrgp.
So there is something happening leading to a change in kernel scales (but not specified in the documentation).. Hello,
How are KernelScales determined for ARD kernels since we cannot choose to optimize these kernels?
Constant initial KernelParameters specified by the user are not the same once the metamodel is created using fitrgp.
So there is something happening leading to a change in kernel scales (but not specified in the documentation).. fitrgp, kernel scales MATLAB Answers — New Questions
Rigol DS1052E Digital Oscilloscope
Hey all!
I want to import data form Rigol DS1052E Digital Oscilloscope into Simulink at run time. Has anyone done this before ? Neither I can’t find the drivers for my Rigol Model nor I know how to do. Will someone help me with this ?
Regards,Hey all!
I want to import data form Rigol DS1052E Digital Oscilloscope into Simulink at run time. Has anyone done this before ? Neither I can’t find the drivers for my Rigol Model nor I know how to do. Will someone help me with this ?
Regards, Hey all!
I want to import data form Rigol DS1052E Digital Oscilloscope into Simulink at run time. Has anyone done this before ? Neither I can’t find the drivers for my Rigol Model nor I know how to do. Will someone help me with this ?
Regards, rigol ds1052e MATLAB Answers — New Questions
How to find the RMSE.. !
I am learning to calculate the RMSE, so i just created the simplest data that i could think of-
a = [2 3 4 5 1 6 3 6 7 8];
years = 1979:1988;
i have used the basic fitting tools to plot the linear trend-
For RMSE, i need the actual data values and estimated data values, how to find the estimated data values or is there a way to just calculate the RMSE?I am learning to calculate the RMSE, so i just created the simplest data that i could think of-
a = [2 3 4 5 1 6 3 6 7 8];
years = 1979:1988;
i have used the basic fitting tools to plot the linear trend-
For RMSE, i need the actual data values and estimated data values, how to find the estimated data values or is there a way to just calculate the RMSE? I am learning to calculate the RMSE, so i just created the simplest data that i could think of-
a = [2 3 4 5 1 6 3 6 7 8];
years = 1979:1988;
i have used the basic fitting tools to plot the linear trend-
For RMSE, i need the actual data values and estimated data values, how to find the estimated data values or is there a way to just calculate the RMSE? rmse, mse, statistics, regression, regstat MATLAB Answers — New Questions
What is the correct input for the Two-sample Kolmogorov-Smirnov test, when I need to compare two histograms?
What is the correct input for the Two-sample Kolmogorov-Smirnov test, when I need to compare two histograms?
Example 1. If the input data are quite similar, it looks like there is no difference in the output of the Two-sample Kolmogorov-Smirnov test, either if I use the original data, "X" and "Y", or the bin counts "NX" and "NY" (returned from the histcounts function), as inputs for the Two-sample Kolmogorov-Smirnov test:
% inputs
X = [2 5 7 10 11 12 13 14 16 17 18 19 22 23 24 29];
Y = [2 5 11 12 13 14 16 17 18 19 20 21 22 23 24 29];
[NX,edgesX] = histcounts(X,’NumBins’,6);
[NY,edgesY] = histcounts(Y,’NumBins’,6);
% plot
hold on
histogram(X,edgesX,’FaceAlpha’,0.1,’EdgeAlpha’,0.8)
histogram(Y,edgesY,’FaceAlpha’,0.1,’EdgeAlpha’,0.2)
% Two-sample Kolmogorov-Smirnov test
[h1,p1,ks2stat1] = kstest2(X,Y); % <– By using the original input data
[h2,p2,ks2stat2] = kstest2(NX,NY); % <– By using the Bin counts "NX" and "NY", returned from the "histcounts" function
table([[h1,p1,ks2stat1];[h2,p2,ks2stat2]] ,’VariableNames’, {‘h | p | ks2stat’},’RowNames’, {‘kstest2(X,Y)’, ‘kstest2(NX,NY)’})
% Reusult of Example 1
ans =
2×1 table
h | p | ks2stat
___________________________________________
kstest2(X,Y) 0 0.999035232339821 0.125
kstest2(NX,NY) 0 0.999956514899259 0.166666666666667
Example 2. If the input data are a bit different, it looks like there is difference in the output of the Two-sample Kolmogorov-Smirnov test, if I use the original data, "X" and "Y", or the bin counts "NX" and "NY" (returned from the histcounts function), as inputs for the Two-sample Kolmogorov-Smirnov test:
% inputs
X = [2 5 7 10 11 12 13 14 16 17 18 19 22 23 24 29];
Y = [2 5 11 12 13 14 16 17 18 19 20 21 22 23 24 29 29 29 29 29 29 29 29];
[NX,edgesX] = histcounts(X,’NumBins’,6);
[NY,edgesY] = histcounts(Y,’NumBins’,6);
% plot
hold on
histogram(X,edgesX,’FaceAlpha’,0.1,’EdgeAlpha’,0.8)
histogram(Y,edgesY,’FaceAlpha’,0.1,’EdgeAlpha’,0.2)
% Two-sample Kolmogorov-Smirnov test
[h1,p1,ks2stat1] = kstest2(X,Y);
[h2,p2,ks2stat2] = kstest2(NX,NY);
table([[h1,p1,ks2stat1];[h2,p2,ks2stat2]] ,’VariableNames’, {‘h | p | ks2stat’},’RowNames’, {‘kstest2(X,Y)’, ‘kstest2(NX,NY)’})
% Result of Example 2
ans =
2×1 table
h | p | ks2stat
___________________________________________
kstest2(X,Y) 0 0.251817384522441 0.315217391304348
kstest2(NX,NY) 0 0.809557310616653 0.333333333333333What is the correct input for the Two-sample Kolmogorov-Smirnov test, when I need to compare two histograms?
Example 1. If the input data are quite similar, it looks like there is no difference in the output of the Two-sample Kolmogorov-Smirnov test, either if I use the original data, "X" and "Y", or the bin counts "NX" and "NY" (returned from the histcounts function), as inputs for the Two-sample Kolmogorov-Smirnov test:
% inputs
X = [2 5 7 10 11 12 13 14 16 17 18 19 22 23 24 29];
Y = [2 5 11 12 13 14 16 17 18 19 20 21 22 23 24 29];
[NX,edgesX] = histcounts(X,’NumBins’,6);
[NY,edgesY] = histcounts(Y,’NumBins’,6);
% plot
hold on
histogram(X,edgesX,’FaceAlpha’,0.1,’EdgeAlpha’,0.8)
histogram(Y,edgesY,’FaceAlpha’,0.1,’EdgeAlpha’,0.2)
% Two-sample Kolmogorov-Smirnov test
[h1,p1,ks2stat1] = kstest2(X,Y); % <– By using the original input data
[h2,p2,ks2stat2] = kstest2(NX,NY); % <– By using the Bin counts "NX" and "NY", returned from the "histcounts" function
table([[h1,p1,ks2stat1];[h2,p2,ks2stat2]] ,’VariableNames’, {‘h | p | ks2stat’},’RowNames’, {‘kstest2(X,Y)’, ‘kstest2(NX,NY)’})
% Reusult of Example 1
ans =
2×1 table
h | p | ks2stat
___________________________________________
kstest2(X,Y) 0 0.999035232339821 0.125
kstest2(NX,NY) 0 0.999956514899259 0.166666666666667
Example 2. If the input data are a bit different, it looks like there is difference in the output of the Two-sample Kolmogorov-Smirnov test, if I use the original data, "X" and "Y", or the bin counts "NX" and "NY" (returned from the histcounts function), as inputs for the Two-sample Kolmogorov-Smirnov test:
% inputs
X = [2 5 7 10 11 12 13 14 16 17 18 19 22 23 24 29];
Y = [2 5 11 12 13 14 16 17 18 19 20 21 22 23 24 29 29 29 29 29 29 29 29];
[NX,edgesX] = histcounts(X,’NumBins’,6);
[NY,edgesY] = histcounts(Y,’NumBins’,6);
% plot
hold on
histogram(X,edgesX,’FaceAlpha’,0.1,’EdgeAlpha’,0.8)
histogram(Y,edgesY,’FaceAlpha’,0.1,’EdgeAlpha’,0.2)
% Two-sample Kolmogorov-Smirnov test
[h1,p1,ks2stat1] = kstest2(X,Y);
[h2,p2,ks2stat2] = kstest2(NX,NY);
table([[h1,p1,ks2stat1];[h2,p2,ks2stat2]] ,’VariableNames’, {‘h | p | ks2stat’},’RowNames’, {‘kstest2(X,Y)’, ‘kstest2(NX,NY)’})
% Result of Example 2
ans =
2×1 table
h | p | ks2stat
___________________________________________
kstest2(X,Y) 0 0.251817384522441 0.315217391304348
kstest2(NX,NY) 0 0.809557310616653 0.333333333333333 What is the correct input for the Two-sample Kolmogorov-Smirnov test, when I need to compare two histograms?
Example 1. If the input data are quite similar, it looks like there is no difference in the output of the Two-sample Kolmogorov-Smirnov test, either if I use the original data, "X" and "Y", or the bin counts "NX" and "NY" (returned from the histcounts function), as inputs for the Two-sample Kolmogorov-Smirnov test:
% inputs
X = [2 5 7 10 11 12 13 14 16 17 18 19 22 23 24 29];
Y = [2 5 11 12 13 14 16 17 18 19 20 21 22 23 24 29];
[NX,edgesX] = histcounts(X,’NumBins’,6);
[NY,edgesY] = histcounts(Y,’NumBins’,6);
% plot
hold on
histogram(X,edgesX,’FaceAlpha’,0.1,’EdgeAlpha’,0.8)
histogram(Y,edgesY,’FaceAlpha’,0.1,’EdgeAlpha’,0.2)
% Two-sample Kolmogorov-Smirnov test
[h1,p1,ks2stat1] = kstest2(X,Y); % <– By using the original input data
[h2,p2,ks2stat2] = kstest2(NX,NY); % <– By using the Bin counts "NX" and "NY", returned from the "histcounts" function
table([[h1,p1,ks2stat1];[h2,p2,ks2stat2]] ,’VariableNames’, {‘h | p | ks2stat’},’RowNames’, {‘kstest2(X,Y)’, ‘kstest2(NX,NY)’})
% Reusult of Example 1
ans =
2×1 table
h | p | ks2stat
___________________________________________
kstest2(X,Y) 0 0.999035232339821 0.125
kstest2(NX,NY) 0 0.999956514899259 0.166666666666667
Example 2. If the input data are a bit different, it looks like there is difference in the output of the Two-sample Kolmogorov-Smirnov test, if I use the original data, "X" and "Y", or the bin counts "NX" and "NY" (returned from the histcounts function), as inputs for the Two-sample Kolmogorov-Smirnov test:
% inputs
X = [2 5 7 10 11 12 13 14 16 17 18 19 22 23 24 29];
Y = [2 5 11 12 13 14 16 17 18 19 20 21 22 23 24 29 29 29 29 29 29 29 29];
[NX,edgesX] = histcounts(X,’NumBins’,6);
[NY,edgesY] = histcounts(Y,’NumBins’,6);
% plot
hold on
histogram(X,edgesX,’FaceAlpha’,0.1,’EdgeAlpha’,0.8)
histogram(Y,edgesY,’FaceAlpha’,0.1,’EdgeAlpha’,0.2)
% Two-sample Kolmogorov-Smirnov test
[h1,p1,ks2stat1] = kstest2(X,Y);
[h2,p2,ks2stat2] = kstest2(NX,NY);
table([[h1,p1,ks2stat1];[h2,p2,ks2stat2]] ,’VariableNames’, {‘h | p | ks2stat’},’RowNames’, {‘kstest2(X,Y)’, ‘kstest2(NX,NY)’})
% Result of Example 2
ans =
2×1 table
h | p | ks2stat
___________________________________________
kstest2(X,Y) 0 0.251817384522441 0.315217391304348
kstest2(NX,NY) 0 0.809557310616653 0.333333333333333 histcounts, kstest2, two-sample kolmogorov-smirnov test, distributions MATLAB Answers — New Questions