Tag Archives: matlab
PCQI code doesn’t showing any output neither any error
I need to take output from a "PCQI: A Patch-Structure Representation Method for Quality Assessment of Contrast Changed Images" code. But whenever i run this, it doesnt show anything at all. Not even an error. How can i solve this?
Demo.m
clc;
clear;
im1=imread(‘ref.png’);
im2=imread(‘contrast_changed.png’);
im1=double(rgb2gray(im1));
im2=double(rgb2gray(im2));
[mpcqi, pcqi_map] = PCQI(im1, im2);
PCQI.m (default value for window = fspecial(‘gaussian’, 11, 1.5); L = 256)
function [mpcqi, pcqi_map]= PCQI(img1, img2, window, L)
if (nargin < 2 || nargin > 4)
mpcqi = -Inf;
pcqi_map = -Inf;
return;
end
if (size(img1) ~= size(img2))
mpcqi = -Inf;
pcqi_map = -Inf;
return;
end
[M N] = size(img1);
if (nargin == 2)
if ((M < 11) || (N < 11))
mpcqi = -Inf;
pcqi_map = -Inf;
return
end
window = fspecial(‘gaussian’, 11, 1.5);
L = 256;
end
if (nargin == 3)
[H W] = size(window);
if ((H*W) < 4 || (H > M) || (W > N))
mpcqi = -Inf;
pcqi_map = -Inf;
return
end
L = 255;
end
if (nargin == 4)
[H W] = size(window);
if ((H*W) < 4 || (H > M) || (W > N))
mpcqi = -Inf;
pcqi_map = -Inf;
return
end
end
window = window/sum(sum(window));
mu1 = filter2(window, img1, ‘valid’);
mu2 = filter2(window, img2, ‘valid’);
mu1_sq = mu1.*mu1;
mu2_sq = mu2.*mu2;
mu1_mu2 = mu1.*mu2;
sigma1_sq = filter2(window, img1.*img1, ‘valid’) – mu1_sq;
sigma2_sq = filter2(window, img2.*img2, ‘valid’) – mu2_sq;
sigma12 = filter2(window, img1.*img2, ‘valid’) – mu1_mu2;
sigma1_sq = max(0, sigma1_sq);
sigma2_sq = max(0, sigma2_sq);
C=3;
pcqi_map = (4/pi) *atan((sigma12 + C )./(sigma1_sq + C ));
pcqi_map = pcqi_map .*((sigma12 + C) ./(sqrt(sigma1_sq).*sqrt(sigma2_sq) + C));
pcqi_map = pcqi_map .*exp(-abs(mu1-mu2)/L);
mpcqi = mean2(pcqi_map);
returnI need to take output from a "PCQI: A Patch-Structure Representation Method for Quality Assessment of Contrast Changed Images" code. But whenever i run this, it doesnt show anything at all. Not even an error. How can i solve this?
Demo.m
clc;
clear;
im1=imread(‘ref.png’);
im2=imread(‘contrast_changed.png’);
im1=double(rgb2gray(im1));
im2=double(rgb2gray(im2));
[mpcqi, pcqi_map] = PCQI(im1, im2);
PCQI.m (default value for window = fspecial(‘gaussian’, 11, 1.5); L = 256)
function [mpcqi, pcqi_map]= PCQI(img1, img2, window, L)
if (nargin < 2 || nargin > 4)
mpcqi = -Inf;
pcqi_map = -Inf;
return;
end
if (size(img1) ~= size(img2))
mpcqi = -Inf;
pcqi_map = -Inf;
return;
end
[M N] = size(img1);
if (nargin == 2)
if ((M < 11) || (N < 11))
mpcqi = -Inf;
pcqi_map = -Inf;
return
end
window = fspecial(‘gaussian’, 11, 1.5);
L = 256;
end
if (nargin == 3)
[H W] = size(window);
if ((H*W) < 4 || (H > M) || (W > N))
mpcqi = -Inf;
pcqi_map = -Inf;
return
end
L = 255;
end
if (nargin == 4)
[H W] = size(window);
if ((H*W) < 4 || (H > M) || (W > N))
mpcqi = -Inf;
pcqi_map = -Inf;
return
end
end
window = window/sum(sum(window));
mu1 = filter2(window, img1, ‘valid’);
mu2 = filter2(window, img2, ‘valid’);
mu1_sq = mu1.*mu1;
mu2_sq = mu2.*mu2;
mu1_mu2 = mu1.*mu2;
sigma1_sq = filter2(window, img1.*img1, ‘valid’) – mu1_sq;
sigma2_sq = filter2(window, img2.*img2, ‘valid’) – mu2_sq;
sigma12 = filter2(window, img1.*img2, ‘valid’) – mu1_mu2;
sigma1_sq = max(0, sigma1_sq);
sigma2_sq = max(0, sigma2_sq);
C=3;
pcqi_map = (4/pi) *atan((sigma12 + C )./(sigma1_sq + C ));
pcqi_map = pcqi_map .*((sigma12 + C) ./(sqrt(sigma1_sq).*sqrt(sigma2_sq) + C));
pcqi_map = pcqi_map .*exp(-abs(mu1-mu2)/L);
mpcqi = mean2(pcqi_map);
return I need to take output from a "PCQI: A Patch-Structure Representation Method for Quality Assessment of Contrast Changed Images" code. But whenever i run this, it doesnt show anything at all. Not even an error. How can i solve this?
Demo.m
clc;
clear;
im1=imread(‘ref.png’);
im2=imread(‘contrast_changed.png’);
im1=double(rgb2gray(im1));
im2=double(rgb2gray(im2));
[mpcqi, pcqi_map] = PCQI(im1, im2);
PCQI.m (default value for window = fspecial(‘gaussian’, 11, 1.5); L = 256)
function [mpcqi, pcqi_map]= PCQI(img1, img2, window, L)
if (nargin < 2 || nargin > 4)
mpcqi = -Inf;
pcqi_map = -Inf;
return;
end
if (size(img1) ~= size(img2))
mpcqi = -Inf;
pcqi_map = -Inf;
return;
end
[M N] = size(img1);
if (nargin == 2)
if ((M < 11) || (N < 11))
mpcqi = -Inf;
pcqi_map = -Inf;
return
end
window = fspecial(‘gaussian’, 11, 1.5);
L = 256;
end
if (nargin == 3)
[H W] = size(window);
if ((H*W) < 4 || (H > M) || (W > N))
mpcqi = -Inf;
pcqi_map = -Inf;
return
end
L = 255;
end
if (nargin == 4)
[H W] = size(window);
if ((H*W) < 4 || (H > M) || (W > N))
mpcqi = -Inf;
pcqi_map = -Inf;
return
end
end
window = window/sum(sum(window));
mu1 = filter2(window, img1, ‘valid’);
mu2 = filter2(window, img2, ‘valid’);
mu1_sq = mu1.*mu1;
mu2_sq = mu2.*mu2;
mu1_mu2 = mu1.*mu2;
sigma1_sq = filter2(window, img1.*img1, ‘valid’) – mu1_sq;
sigma2_sq = filter2(window, img2.*img2, ‘valid’) – mu2_sq;
sigma12 = filter2(window, img1.*img2, ‘valid’) – mu1_mu2;
sigma1_sq = max(0, sigma1_sq);
sigma2_sq = max(0, sigma2_sq);
C=3;
pcqi_map = (4/pi) *atan((sigma12 + C )./(sigma1_sq + C ));
pcqi_map = pcqi_map .*((sigma12 + C) ./(sqrt(sigma1_sq).*sqrt(sigma2_sq) + C));
pcqi_map = pcqi_map .*exp(-abs(mu1-mu2)/L);
mpcqi = mean2(pcqi_map);
return image analysis, pcqi MATLAB Answers — New Questions
Simulink Project Change Resource Folder Location
Currently, I have a 2020a Simulink project where the resource folder is located in "resources". My group is trying to change that "resources" folder to ".SimulinkProject" but we cannot find where to do that. The Matlab preferences has the location as the preferred one already.
Is there a way to migrate that location?Currently, I have a 2020a Simulink project where the resource folder is located in "resources". My group is trying to change that "resources" folder to ".SimulinkProject" but we cannot find where to do that. The Matlab preferences has the location as the preferred one already.
Is there a way to migrate that location? Currently, I have a 2020a Simulink project where the resource folder is located in "resources". My group is trying to change that "resources" folder to ".SimulinkProject" but we cannot find where to do that. The Matlab preferences has the location as the preferred one already.
Is there a way to migrate that location? simulink, project MATLAB Answers — New Questions
Best way to retrieve items from a cell array using a cell array of indices?
Hi I am porting a script I had in Python to Matlab. Also returning to MATLAB after a decade, so pardon me if it’s too basic.
The key issue I am having is, retrieving premapped items from a cell array. Example, I have:
label_names={"assds", "Sasas", "Asasa", "assds"}
indices={[1 3 2]} %note that this can have varying lengths from 1 to full length of the label array.
label_names(indices) %of course returns an error
Error is "Unable to use a value of type cell as an index."
What is the best way to achieve this – retreive items based on a cell array of indices – as cleanly as possible?
PS: The reason they are cell arrays has to do with varying lengths. To avoid X-Y problem, lets assume rest of the code is done optimally.
Thanks!Hi I am porting a script I had in Python to Matlab. Also returning to MATLAB after a decade, so pardon me if it’s too basic.
The key issue I am having is, retrieving premapped items from a cell array. Example, I have:
label_names={"assds", "Sasas", "Asasa", "assds"}
indices={[1 3 2]} %note that this can have varying lengths from 1 to full length of the label array.
label_names(indices) %of course returns an error
Error is "Unable to use a value of type cell as an index."
What is the best way to achieve this – retreive items based on a cell array of indices – as cleanly as possible?
PS: The reason they are cell arrays has to do with varying lengths. To avoid X-Y problem, lets assume rest of the code is done optimally.
Thanks! Hi I am porting a script I had in Python to Matlab. Also returning to MATLAB after a decade, so pardon me if it’s too basic.
The key issue I am having is, retrieving premapped items from a cell array. Example, I have:
label_names={"assds", "Sasas", "Asasa", "assds"}
indices={[1 3 2]} %note that this can have varying lengths from 1 to full length of the label array.
label_names(indices) %of course returns an error
Error is "Unable to use a value of type cell as an index."
What is the best way to achieve this – retreive items based on a cell array of indices – as cleanly as possible?
PS: The reason they are cell arrays has to do with varying lengths. To avoid X-Y problem, lets assume rest of the code is done optimally.
Thanks! cell array, indexing MATLAB Answers — New Questions
Stereo camera calibration app not see images in folder to upload while camera calibration app can still see
Hello there,
Stereo camera calibration app not see images in folder to upload while camera calibration app can still see
I tried both jpg & png images
Sincerely yours,
Truong MaiHello there,
Stereo camera calibration app not see images in folder to upload while camera calibration app can still see
I tried both jpg & png images
Sincerely yours,
Truong Mai Hello there,
Stereo camera calibration app not see images in folder to upload while camera calibration app can still see
I tried both jpg & png images
Sincerely yours,
Truong Mai stereo camera calibration MATLAB Answers — New Questions
Finding a circle in a 2D array
This is not circle finding in an image, which has been well covered, but in an array.
I have an array P with several approximately-circular areas of a low value. I would like to find the centres of those areas to calibrate my device. Here is a contour 2D plot of P. The contour plot looks a bit odd because I only obtained a patch of data around each circle (the box) and it is doing a linear interpolation between those.
This is a one-time calibration so I’m happy to do some manual setting up work.
Thanks in advance!
Jack
This is how I display the contour:
figure(1)
pcolor(X,Y,P);
shading interp
hold on
colorbar
hold off
PS this is my first question so do say if there is anything I can improve for next time.This is not circle finding in an image, which has been well covered, but in an array.
I have an array P with several approximately-circular areas of a low value. I would like to find the centres of those areas to calibrate my device. Here is a contour 2D plot of P. The contour plot looks a bit odd because I only obtained a patch of data around each circle (the box) and it is doing a linear interpolation between those.
This is a one-time calibration so I’m happy to do some manual setting up work.
Thanks in advance!
Jack
This is how I display the contour:
figure(1)
pcolor(X,Y,P);
shading interp
hold on
colorbar
hold off
PS this is my first question so do say if there is anything I can improve for next time. This is not circle finding in an image, which has been well covered, but in an array.
I have an array P with several approximately-circular areas of a low value. I would like to find the centres of those areas to calibrate my device. Here is a contour 2D plot of P. The contour plot looks a bit odd because I only obtained a patch of data around each circle (the box) and it is doing a linear interpolation between those.
This is a one-time calibration so I’m happy to do some manual setting up work.
Thanks in advance!
Jack
This is how I display the contour:
figure(1)
pcolor(X,Y,P);
shading interp
hold on
colorbar
hold off
PS this is my first question so do say if there is anything I can improve for next time. circles, finding, arrays, variables, matlab MATLAB Answers — New Questions
Simulink random number generation same seed in model and code generation
The Simulink Random Number block allows seeding with a positive integer (as a double type). When generating C code the seed is converted to a uint32 but it is not obvious how.
I can call the generated code and set a seed (as a uint32), how could i set the same seed in the Simulink Model? I need to run from the same seed in both Simulink and C, being able to set each at the start of a run (rather than regenerate C with new seed)The Simulink Random Number block allows seeding with a positive integer (as a double type). When generating C code the seed is converted to a uint32 but it is not obvious how.
I can call the generated code and set a seed (as a uint32), how could i set the same seed in the Simulink Model? I need to run from the same seed in both Simulink and C, being able to set each at the start of a run (rather than regenerate C with new seed) The Simulink Random Number block allows seeding with a positive integer (as a double type). When generating C code the seed is converted to a uint32 but it is not obvious how.
I can call the generated code and set a seed (as a uint32), how could i set the same seed in the Simulink Model? I need to run from the same seed in both Simulink and C, being able to set each at the start of a run (rather than regenerate C with new seed) simulink, random number generator MATLAB Answers — New Questions
Capturing Lossless Images with Image Acquisition Toolbox (getsnasphot)
Hello everyone,
This is a follow-up to an earlier question I had asked about capturing lossless images with Matlab. Earlier, I was using USB Webcam Package’s snapshot() function to capture, yet it seemed that there was some compression going on possibly because it was not possible to access YUY2 (I am not sure if this is relevant as I want to capture images rather than recording videos). Now I have moved on to use the Image Acquisition Toolbox and the interface generated the following code to capture images:
v = videoinput("winvideo", 1, "YUY2_3840x2160"); % Video device
v.ReturnedColorspace = "RGB";
src = getselectedsource(v);
src.Exposure = 0; % Camera parameters
image1 = getsnapshot(v); % Capturing the image
filename = "snapshot1.bmp"; % I changed the code to save the image as .bmp
imwrite(image1, filename, "bmp"); % Saving the file
Now the code is using the getsnapshot() function instead. Should this apply any additional compression on Matlab’s side of things? I know that the camera may do something but I want to ensure that Matlab does not.Hello everyone,
This is a follow-up to an earlier question I had asked about capturing lossless images with Matlab. Earlier, I was using USB Webcam Package’s snapshot() function to capture, yet it seemed that there was some compression going on possibly because it was not possible to access YUY2 (I am not sure if this is relevant as I want to capture images rather than recording videos). Now I have moved on to use the Image Acquisition Toolbox and the interface generated the following code to capture images:
v = videoinput("winvideo", 1, "YUY2_3840x2160"); % Video device
v.ReturnedColorspace = "RGB";
src = getselectedsource(v);
src.Exposure = 0; % Camera parameters
image1 = getsnapshot(v); % Capturing the image
filename = "snapshot1.bmp"; % I changed the code to save the image as .bmp
imwrite(image1, filename, "bmp"); % Saving the file
Now the code is using the getsnapshot() function instead. Should this apply any additional compression on Matlab’s side of things? I know that the camera may do something but I want to ensure that Matlab does not. Hello everyone,
This is a follow-up to an earlier question I had asked about capturing lossless images with Matlab. Earlier, I was using USB Webcam Package’s snapshot() function to capture, yet it seemed that there was some compression going on possibly because it was not possible to access YUY2 (I am not sure if this is relevant as I want to capture images rather than recording videos). Now I have moved on to use the Image Acquisition Toolbox and the interface generated the following code to capture images:
v = videoinput("winvideo", 1, "YUY2_3840x2160"); % Video device
v.ReturnedColorspace = "RGB";
src = getselectedsource(v);
src.Exposure = 0; % Camera parameters
image1 = getsnapshot(v); % Capturing the image
filename = "snapshot1.bmp"; % I changed the code to save the image as .bmp
imwrite(image1, filename, "bmp"); % Saving the file
Now the code is using the getsnapshot() function instead. Should this apply any additional compression on Matlab’s side of things? I know that the camera may do something but I want to ensure that Matlab does not. image acquisition, lossless image, bitmap, camera, recording, video, image MATLAB Answers — New Questions
reference model building error in simulink realtime using speedgoat library 2024b
I have reference 3 model inside main model while build the main model in simulink realtime i am getting this error, these models are compiling/building individually.
Error : ### Checking status of model reference code generation target for model ‘abcd’ used in ‘MasterSpeedgoatModel’.
### Model reference code generation target (abcd.cpp) for model SwDev_IO_V2 was out of date. Binary information cache did not exist. slprj folder containing binary information cache might have been removed.
### Starting build procedure for: abcd ### Generating code and artifacts to ‘Model specific’ folder structure
Model reference code generation targets:
Model Build Reason Status Build Duration
=======================================================================================================================================
abcd Information cache folder or artifacts were missing. Failed to build. For more information, see build log. 0d
Top model targets:
Model Build Reason Status Build Duration
================================================================================================================================================
MainModel Information cache folder or artifacts were missing. Failed to build. For more information, see build log. 0d
0 of 4 models built (1 models already up to date)
Error:Error(s) encountered while building "abcd_rtwlib"I have reference 3 model inside main model while build the main model in simulink realtime i am getting this error, these models are compiling/building individually.
Error : ### Checking status of model reference code generation target for model ‘abcd’ used in ‘MasterSpeedgoatModel’.
### Model reference code generation target (abcd.cpp) for model SwDev_IO_V2 was out of date. Binary information cache did not exist. slprj folder containing binary information cache might have been removed.
### Starting build procedure for: abcd ### Generating code and artifacts to ‘Model specific’ folder structure
Model reference code generation targets:
Model Build Reason Status Build Duration
=======================================================================================================================================
abcd Information cache folder or artifacts were missing. Failed to build. For more information, see build log. 0d
Top model targets:
Model Build Reason Status Build Duration
================================================================================================================================================
MainModel Information cache folder or artifacts were missing. Failed to build. For more information, see build log. 0d
0 of 4 models built (1 models already up to date)
Error:Error(s) encountered while building "abcd_rtwlib" I have reference 3 model inside main model while build the main model in simulink realtime i am getting this error, these models are compiling/building individually.
Error : ### Checking status of model reference code generation target for model ‘abcd’ used in ‘MasterSpeedgoatModel’.
### Model reference code generation target (abcd.cpp) for model SwDev_IO_V2 was out of date. Binary information cache did not exist. slprj folder containing binary information cache might have been removed.
### Starting build procedure for: abcd ### Generating code and artifacts to ‘Model specific’ folder structure
Model reference code generation targets:
Model Build Reason Status Build Duration
=======================================================================================================================================
abcd Information cache folder or artifacts were missing. Failed to build. For more information, see build log. 0d
Top model targets:
Model Build Reason Status Build Duration
================================================================================================================================================
MainModel Information cache folder or artifacts were missing. Failed to build. For more information, see build log. 0d
0 of 4 models built (1 models already up to date)
Error:Error(s) encountered while building "abcd_rtwlib" simulink real time, speedgoat, library, io142, simulink, matlab 2024b MATLAB Answers — New Questions
array indices must be positive integers or logical values when complier matlab file – Application complier
Hi,
I have developed a function to be converted into exe file, the function include optimizer fmincon. The function is working well from matlab but when I converted into exe file using Application complier and start to run the exe file, the optimizer fmincon have this error "array indices must be positive integers or logical values".
Not sure what is wrong. Any help.Hi,
I have developed a function to be converted into exe file, the function include optimizer fmincon. The function is working well from matlab but when I converted into exe file using Application complier and start to run the exe file, the optimizer fmincon have this error "array indices must be positive integers or logical values".
Not sure what is wrong. Any help. Hi,
I have developed a function to be converted into exe file, the function include optimizer fmincon. The function is working well from matlab but when I converted into exe file using Application complier and start to run the exe file, the optimizer fmincon have this error "array indices must be positive integers or logical values".
Not sure what is wrong. Any help. application complier, fmincon, array indices must be positive integers or logical MATLAB Answers — New Questions
How to Call “convenc” DLL Compiled with MATLAB Library Compiler in VS2019?
Has anyone experienced compiling the MATLAB built-in function "convenc" into a DLL using the MATLAB Library Compiler and then calling it in VS2019 for development? If you have any related experience or steps to share, I would greatly appreciate it!Has anyone experienced compiling the MATLAB built-in function "convenc" into a DLL using the MATLAB Library Compiler and then calling it in VS2019 for development? If you have any related experience or steps to share, I would greatly appreciate it! Has anyone experienced compiling the MATLAB built-in function "convenc" into a DLL using the MATLAB Library Compiler and then calling it in VS2019 for development? If you have any related experience or steps to share, I would greatly appreciate it! convenc, library compiler MATLAB Answers — New Questions
nested loops to find values then execute commands
I have written a script to find the maximum and minimum values of 4 time series and then truncate each time series to these values as they are all of different length.
I want it to record the maximum and minimum values of all the time series first (lines 15-19), then after that store the overall smallest and largest values to new variables (lines 20-23).
At the moment, its constantly updating variables as it loops through, so its not using the overall smallest/largest values to truncate the time series.
I have tried putting lines 15-19 in another loop so it executes this first, but it doesnt seem to make any difference. Can anybody help?
%import all the csv files in the folder
csvFiles = dir(fullfile(folderPath, ‘*.csv’));
%read in all the csv files
for i = 1:length(csvFiles)
%get the individual file pathway
csvFilePath = fullfile(folderPath, csvFiles(i).name);
%read the file in
data = readmatrix(csvFilePath);
%remove nan’s from the timeseries
data = data(~any(isnan(data), 2), :);
%remove non-unique datapoints from the timeseries
[~, id] = unique(data(:,1)) ;
data = data(id,:);
for a = 1:length(csvFiles)
%find and save the maximum value of all the time series
maxVal(1) = max(data(:,1));
%find and save the minimum value of all the time series
minVal(1) = min(data(:,1));
%find and save the mean dt of all the time series
dt(1) = mean(diff(data(:,1)));
end
%find the time series that ends soonest
smallestMaxValue = min(maxVal)
%find the time series that starts latest
largestMinValue = max(minVal)
%truncate all the time series to the shortest one
truncateRow = find(data(:,1) > smallestMaxValue, 1, ‘first’); %find the index of the first value in the first column when the shortest time series is exceeded
if ~isempty(truncateRow)
truncatedData = data(1:truncateRow-1, :); %if there is a value in truncateRow, then truncate the dataset up to this point
else
truncatedData = data; %if there is no value in truncateRow (e.g. shortest time series), then leave the data as it is
end
endI have written a script to find the maximum and minimum values of 4 time series and then truncate each time series to these values as they are all of different length.
I want it to record the maximum and minimum values of all the time series first (lines 15-19), then after that store the overall smallest and largest values to new variables (lines 20-23).
At the moment, its constantly updating variables as it loops through, so its not using the overall smallest/largest values to truncate the time series.
I have tried putting lines 15-19 in another loop so it executes this first, but it doesnt seem to make any difference. Can anybody help?
%import all the csv files in the folder
csvFiles = dir(fullfile(folderPath, ‘*.csv’));
%read in all the csv files
for i = 1:length(csvFiles)
%get the individual file pathway
csvFilePath = fullfile(folderPath, csvFiles(i).name);
%read the file in
data = readmatrix(csvFilePath);
%remove nan’s from the timeseries
data = data(~any(isnan(data), 2), :);
%remove non-unique datapoints from the timeseries
[~, id] = unique(data(:,1)) ;
data = data(id,:);
for a = 1:length(csvFiles)
%find and save the maximum value of all the time series
maxVal(1) = max(data(:,1));
%find and save the minimum value of all the time series
minVal(1) = min(data(:,1));
%find and save the mean dt of all the time series
dt(1) = mean(diff(data(:,1)));
end
%find the time series that ends soonest
smallestMaxValue = min(maxVal)
%find the time series that starts latest
largestMinValue = max(minVal)
%truncate all the time series to the shortest one
truncateRow = find(data(:,1) > smallestMaxValue, 1, ‘first’); %find the index of the first value in the first column when the shortest time series is exceeded
if ~isempty(truncateRow)
truncatedData = data(1:truncateRow-1, :); %if there is a value in truncateRow, then truncate the dataset up to this point
else
truncatedData = data; %if there is no value in truncateRow (e.g. shortest time series), then leave the data as it is
end
end I have written a script to find the maximum and minimum values of 4 time series and then truncate each time series to these values as they are all of different length.
I want it to record the maximum and minimum values of all the time series first (lines 15-19), then after that store the overall smallest and largest values to new variables (lines 20-23).
At the moment, its constantly updating variables as it loops through, so its not using the overall smallest/largest values to truncate the time series.
I have tried putting lines 15-19 in another loop so it executes this first, but it doesnt seem to make any difference. Can anybody help?
%import all the csv files in the folder
csvFiles = dir(fullfile(folderPath, ‘*.csv’));
%read in all the csv files
for i = 1:length(csvFiles)
%get the individual file pathway
csvFilePath = fullfile(folderPath, csvFiles(i).name);
%read the file in
data = readmatrix(csvFilePath);
%remove nan’s from the timeseries
data = data(~any(isnan(data), 2), :);
%remove non-unique datapoints from the timeseries
[~, id] = unique(data(:,1)) ;
data = data(id,:);
for a = 1:length(csvFiles)
%find and save the maximum value of all the time series
maxVal(1) = max(data(:,1));
%find and save the minimum value of all the time series
minVal(1) = min(data(:,1));
%find and save the mean dt of all the time series
dt(1) = mean(diff(data(:,1)));
end
%find the time series that ends soonest
smallestMaxValue = min(maxVal)
%find the time series that starts latest
largestMinValue = max(minVal)
%truncate all the time series to the shortest one
truncateRow = find(data(:,1) > smallestMaxValue, 1, ‘first’); %find the index of the first value in the first column when the shortest time series is exceeded
if ~isempty(truncateRow)
truncatedData = data(1:truncateRow-1, :); %if there is a value in truncateRow, then truncate the dataset up to this point
else
truncatedData = data; %if there is no value in truncateRow (e.g. shortest time series), then leave the data as it is
end
end for loop, loop, nested loop MATLAB Answers — New Questions
How to classify using PCA (“pcares” function)
Hello.
I want to do a video classification.
I found some function about PCA.
https://www.mathworks.com/help/stats/pcares.html
[residuals,reconstructed] = pcares(X,5)
After using pcares(X,5), Can I classify data using "reconstructed"?
I mean, "reconstructed" is 3600 x 25.
1. After flattening each data, I got 90000 X 1.
2. I have 90 data, so I got 90 X 90001 (the last column is class).
3. Using classification methods like SVM, KNN, etc.
4. calculate the accuracy of the classification.
Is it a reasonable approach? or do I need to use other methods as PCA not "pcares".
When I use "reconstructed" data after "pcares", the accuracy of classification is so low.
Please let me know how to deal with this issue.Hello.
I want to do a video classification.
I found some function about PCA.
https://www.mathworks.com/help/stats/pcares.html
[residuals,reconstructed] = pcares(X,5)
After using pcares(X,5), Can I classify data using "reconstructed"?
I mean, "reconstructed" is 3600 x 25.
1. After flattening each data, I got 90000 X 1.
2. I have 90 data, so I got 90 X 90001 (the last column is class).
3. Using classification methods like SVM, KNN, etc.
4. calculate the accuracy of the classification.
Is it a reasonable approach? or do I need to use other methods as PCA not "pcares".
When I use "reconstructed" data after "pcares", the accuracy of classification is so low.
Please let me know how to deal with this issue. Hello.
I want to do a video classification.
I found some function about PCA.
https://www.mathworks.com/help/stats/pcares.html
[residuals,reconstructed] = pcares(X,5)
After using pcares(X,5), Can I classify data using "reconstructed"?
I mean, "reconstructed" is 3600 x 25.
1. After flattening each data, I got 90000 X 1.
2. I have 90 data, so I got 90 X 90001 (the last column is class).
3. Using classification methods like SVM, KNN, etc.
4. calculate the accuracy of the classification.
Is it a reasonable approach? or do I need to use other methods as PCA not "pcares".
When I use "reconstructed" data after "pcares", the accuracy of classification is so low.
Please let me know how to deal with this issue. classification, class, pca, dimensionality reduction, image analysis MATLAB Answers — New Questions
Why does Matlab crash when I try to access .NET 6.0 (core)?
Note: Workaround is to remove .NET 9.0 from PC to resolve conflicts with 6.0.
This might be a .NET issue as a whole, but I only see it using Matlab, so I am posting here to help others out facing the same issues.
I have a .dll from one of the groups I work with for communicating to our devices. The .dll was built in .NET 6.0 (core) (x64). I have been able to use it in the past in Matlab, but have now run into issues since installing Visual Studio 2022. It was discovered that Matlab would reference the most recent installation of .NET (9.0 in my case) which was installed by VS 2022. When I set "core" as the environment in Matlab (dotnetenv("core")), I would then make the .NET assembly visible to Matlab using NET.addAssembly("insert path here"). When Matlab got to this step, it would buffer for about 10 seconds then crash immediately with no crash report. Getting help from my local IT, we pin pointed it to the .NET 9.0 install causing the problem.
To get around this, you can either uninstall 9.0 or set up an environment variable in your system properties called "DOTNET_ROOT" that can force a path to be referenced.
So I would like to ask if anyone else has faced this issue in Matlab? Is it an unexpected error that needs an error handle? I am naive to .net, and really only know the particular dll I interact with to do my methods, etc.Note: Workaround is to remove .NET 9.0 from PC to resolve conflicts with 6.0.
This might be a .NET issue as a whole, but I only see it using Matlab, so I am posting here to help others out facing the same issues.
I have a .dll from one of the groups I work with for communicating to our devices. The .dll was built in .NET 6.0 (core) (x64). I have been able to use it in the past in Matlab, but have now run into issues since installing Visual Studio 2022. It was discovered that Matlab would reference the most recent installation of .NET (9.0 in my case) which was installed by VS 2022. When I set "core" as the environment in Matlab (dotnetenv("core")), I would then make the .NET assembly visible to Matlab using NET.addAssembly("insert path here"). When Matlab got to this step, it would buffer for about 10 seconds then crash immediately with no crash report. Getting help from my local IT, we pin pointed it to the .NET 9.0 install causing the problem.
To get around this, you can either uninstall 9.0 or set up an environment variable in your system properties called "DOTNET_ROOT" that can force a path to be referenced.
So I would like to ask if anyone else has faced this issue in Matlab? Is it an unexpected error that needs an error handle? I am naive to .net, and really only know the particular dll I interact with to do my methods, etc. Note: Workaround is to remove .NET 9.0 from PC to resolve conflicts with 6.0.
This might be a .NET issue as a whole, but I only see it using Matlab, so I am posting here to help others out facing the same issues.
I have a .dll from one of the groups I work with for communicating to our devices. The .dll was built in .NET 6.0 (core) (x64). I have been able to use it in the past in Matlab, but have now run into issues since installing Visual Studio 2022. It was discovered that Matlab would reference the most recent installation of .NET (9.0 in my case) which was installed by VS 2022. When I set "core" as the environment in Matlab (dotnetenv("core")), I would then make the .NET assembly visible to Matlab using NET.addAssembly("insert path here"). When Matlab got to this step, it would buffer for about 10 seconds then crash immediately with no crash report. Getting help from my local IT, we pin pointed it to the .NET 9.0 install causing the problem.
To get around this, you can either uninstall 9.0 or set up an environment variable in your system properties called "DOTNET_ROOT" that can force a path to be referenced.
So I would like to ask if anyone else has faced this issue in Matlab? Is it an unexpected error that needs an error handle? I am naive to .net, and really only know the particular dll I interact with to do my methods, etc. .net MATLAB Answers — New Questions
Large Gregorian Antenna simulations at high frequency
If I have a large Gregorian antenna (2-3 meter) and need to operate it in frequency range 20/30 GHz, I get a problem of out of memory and need RAM in range of 200G or more !! Is there a solution to this issue? By decreasing number of iterations or decrease accuracy needed ?If I have a large Gregorian antenna (2-3 meter) and need to operate it in frequency range 20/30 GHz, I get a problem of out of memory and need RAM in range of 200G or more !! Is there a solution to this issue? By decreasing number of iterations or decrease accuracy needed ? If I have a large Gregorian antenna (2-3 meter) and need to operate it in frequency range 20/30 GHz, I get a problem of out of memory and need RAM in range of 200G or more !! Is there a solution to this issue? By decreasing number of iterations or decrease accuracy needed ? antenna, high frequency MATLAB Answers — New Questions
VPP Virtual Power Plants model SIMULINK
Hello everyone! Can I have some files about VPP Virtual Power Plants research for reference during my studies? Please help me.Hello everyone! Can I have some files about VPP Virtual Power Plants research for reference during my studies? Please help me. Hello everyone! Can I have some files about VPP Virtual Power Plants research for reference during my studies? Please help me. vpp, model MATLAB Answers — New Questions
lsqlin and its constraints
Hi,
How does MATLAB impose the Upper and Lower Bound on the
unknowns in the lsqlin routine?
Does it build a quadratic format of the constraints and ads it to the solution?!Hi,
How does MATLAB impose the Upper and Lower Bound on the
unknowns in the lsqlin routine?
Does it build a quadratic format of the constraints and ads it to the solution?! Hi,
How does MATLAB impose the Upper and Lower Bound on the
unknowns in the lsqlin routine?
Does it build a quadratic format of the constraints and ads it to the solution?! optimization, curve fitting MATLAB Answers — New Questions
How to defined Binary variables with equality and inequality Constraints while using Genetic Algorithm?
I defined equality and inequality constraints and for binary variables I used IntCon, But then ga gives error that equality constraints cannot used with integer. But I need equality and inequality constraints with binary variables to get satisfy result.
If anyone know, how to used both constraints with binary variables and integer please tell me.I defined equality and inequality constraints and for binary variables I used IntCon, But then ga gives error that equality constraints cannot used with integer. But I need equality and inequality constraints with binary variables to get satisfy result.
If anyone know, how to used both constraints with binary variables and integer please tell me. I defined equality and inequality constraints and for binary variables I used IntCon, But then ga gives error that equality constraints cannot used with integer. But I need equality and inequality constraints with binary variables to get satisfy result.
If anyone know, how to used both constraints with binary variables and integer please tell me. binary variables with equality constraints, integer variables with equality constraints MATLAB Answers — New Questions
Code generation paths of model references
Hi,
I have a top model in which there are several model references.
If I generate code, code of top model is generated in folder:
code_generationtop_model_ert_rtw
code of model references is generated into:
code_generationslprjertmodel_reference1
code_generationslprjertmodel_reference2
code_generationslprjertmodel_reference3
…
and there is also:
code_generationslprjertshared_utils
If I have for example 100 different model references in my top model, and if I would like to link external IDE enviroment directly to code generation directory in simulink project, I would have to set 100 paths in IDE enviroment (metrowerks eclipse 10.5).
Is it possible to compact the code of model references in single file, or is it possible to generate all .c, .h files into one directory.
Or any other suggestion would be welcomed.
Thank you and best regards,
DejanHi,
I have a top model in which there are several model references.
If I generate code, code of top model is generated in folder:
code_generationtop_model_ert_rtw
code of model references is generated into:
code_generationslprjertmodel_reference1
code_generationslprjertmodel_reference2
code_generationslprjertmodel_reference3
…
and there is also:
code_generationslprjertshared_utils
If I have for example 100 different model references in my top model, and if I would like to link external IDE enviroment directly to code generation directory in simulink project, I would have to set 100 paths in IDE enviroment (metrowerks eclipse 10.5).
Is it possible to compact the code of model references in single file, or is it possible to generate all .c, .h files into one directory.
Or any other suggestion would be welcomed.
Thank you and best regards,
Dejan Hi,
I have a top model in which there are several model references.
If I generate code, code of top model is generated in folder:
code_generationtop_model_ert_rtw
code of model references is generated into:
code_generationslprjertmodel_reference1
code_generationslprjertmodel_reference2
code_generationslprjertmodel_reference3
…
and there is also:
code_generationslprjertshared_utils
If I have for example 100 different model references in my top model, and if I would like to link external IDE enviroment directly to code generation directory in simulink project, I would have to set 100 paths in IDE enviroment (metrowerks eclipse 10.5).
Is it possible to compact the code of model references in single file, or is it possible to generate all .c, .h files into one directory.
Or any other suggestion would be welcomed.
Thank you and best regards,
Dejan code generation path MATLAB Answers — New Questions
delay and sum beamforming
I am making a program to acheive delay and sum beamforming,
I looked for examples of this online and found one relatable. The code is given below. When i run the program i get this error
%% Examples on delay-and-sum response for different arrays and input signals
%% 1D-array case
% Create vectors of x- and y-coordinates of microphone positions
xPos = -0.8:0.2:0.8; % 1xP vector of x-positions [m]
yPos = zeros(1, numel(xPos)); % 1xP vector of y-positions [m]
zPos = zeros(1, numel(xPos));
elementWeights = ones(1, numel(xPos))/numel(xPos); % 1xP vector of weightings
% Define arriving angles and frequency of input signals
thetaArrivalAngles = [-30 10]; % degrees
phiArrivalAngles = [0 0]; % degrees
f = 800; % [Hz]
c = 340; % [m/s]
fs = 44.1e3; % [Hz]
% Define array scanning angles (1D, so phi = 0)
thetaScanAngles = -90:0.1:90; % degrees
phiScanAngles = 0; % degrees
% Create input signal
inputSignal = createSignal(xPos, yPos, zPos, f, c, fs, thetaArrivalAngles, phiArrivalAngles);
% Create steering vector/matrix
e = steeringVector(xPos, yPos, zPos, f, c, thetaScanAngles, phiScanAngles);
% Create cross spectral matrix
R = crossSpectralMatrix(inputSignal);
% Calculate delay-and-sum steered response
S = steeredResponseDelayAndSum(R, e, elementWeights);
%Normalise spectrum
spectrumNormalized = abs(S)/max(abs(S));
%Convert to decibel
spectrumLog = 10*log10(spectrumNormalized);
%Plot array
fig1 = figure;
fig1.Color = ‘w’;
ax = axes(‘Parent’, fig1);
scatter(ax, xPos, yPos, 20, ‘filled’)
axis(ax, ‘square’)
ax.XLim = [-1 1];
ax.YLim = [-1 1];
grid(ax, ‘on’)
title(ax, ‘Microphone positions’)
%Plot steered response with indicator lines
fig2 = figure;
fig2.Color = ‘w’;
ax = axes(‘Parent’, fig2);
plot(ax, thetaScanAngles, spectrumLog)
grid(ax, ‘on’)
ax.XLim = [thetaScanAngles(1) thetaScanAngles(end)];
for j=1:numel(thetaArrivalAngles)
indx = find(thetaScanAngles >= thetaArrivalAngles(j), 1);
line(ax, [thetaScanAngles(indx) thetaScanAngles(indx)], ax.YLim,’LineWidth’, 1, ‘Color’, ‘r’, ‘LineStyle’, ‘–‘);
end
xlabel(ax, ‘theta’)
ylabel(ax, ‘dB’)I am making a program to acheive delay and sum beamforming,
I looked for examples of this online and found one relatable. The code is given below. When i run the program i get this error
%% Examples on delay-and-sum response for different arrays and input signals
%% 1D-array case
% Create vectors of x- and y-coordinates of microphone positions
xPos = -0.8:0.2:0.8; % 1xP vector of x-positions [m]
yPos = zeros(1, numel(xPos)); % 1xP vector of y-positions [m]
zPos = zeros(1, numel(xPos));
elementWeights = ones(1, numel(xPos))/numel(xPos); % 1xP vector of weightings
% Define arriving angles and frequency of input signals
thetaArrivalAngles = [-30 10]; % degrees
phiArrivalAngles = [0 0]; % degrees
f = 800; % [Hz]
c = 340; % [m/s]
fs = 44.1e3; % [Hz]
% Define array scanning angles (1D, so phi = 0)
thetaScanAngles = -90:0.1:90; % degrees
phiScanAngles = 0; % degrees
% Create input signal
inputSignal = createSignal(xPos, yPos, zPos, f, c, fs, thetaArrivalAngles, phiArrivalAngles);
% Create steering vector/matrix
e = steeringVector(xPos, yPos, zPos, f, c, thetaScanAngles, phiScanAngles);
% Create cross spectral matrix
R = crossSpectralMatrix(inputSignal);
% Calculate delay-and-sum steered response
S = steeredResponseDelayAndSum(R, e, elementWeights);
%Normalise spectrum
spectrumNormalized = abs(S)/max(abs(S));
%Convert to decibel
spectrumLog = 10*log10(spectrumNormalized);
%Plot array
fig1 = figure;
fig1.Color = ‘w’;
ax = axes(‘Parent’, fig1);
scatter(ax, xPos, yPos, 20, ‘filled’)
axis(ax, ‘square’)
ax.XLim = [-1 1];
ax.YLim = [-1 1];
grid(ax, ‘on’)
title(ax, ‘Microphone positions’)
%Plot steered response with indicator lines
fig2 = figure;
fig2.Color = ‘w’;
ax = axes(‘Parent’, fig2);
plot(ax, thetaScanAngles, spectrumLog)
grid(ax, ‘on’)
ax.XLim = [thetaScanAngles(1) thetaScanAngles(end)];
for j=1:numel(thetaArrivalAngles)
indx = find(thetaScanAngles >= thetaArrivalAngles(j), 1);
line(ax, [thetaScanAngles(indx) thetaScanAngles(indx)], ax.YLim,’LineWidth’, 1, ‘Color’, ‘r’, ‘LineStyle’, ‘–‘);
end
xlabel(ax, ‘theta’)
ylabel(ax, ‘dB’) I am making a program to acheive delay and sum beamforming,
I looked for examples of this online and found one relatable. The code is given below. When i run the program i get this error
%% Examples on delay-and-sum response for different arrays and input signals
%% 1D-array case
% Create vectors of x- and y-coordinates of microphone positions
xPos = -0.8:0.2:0.8; % 1xP vector of x-positions [m]
yPos = zeros(1, numel(xPos)); % 1xP vector of y-positions [m]
zPos = zeros(1, numel(xPos));
elementWeights = ones(1, numel(xPos))/numel(xPos); % 1xP vector of weightings
% Define arriving angles and frequency of input signals
thetaArrivalAngles = [-30 10]; % degrees
phiArrivalAngles = [0 0]; % degrees
f = 800; % [Hz]
c = 340; % [m/s]
fs = 44.1e3; % [Hz]
% Define array scanning angles (1D, so phi = 0)
thetaScanAngles = -90:0.1:90; % degrees
phiScanAngles = 0; % degrees
% Create input signal
inputSignal = createSignal(xPos, yPos, zPos, f, c, fs, thetaArrivalAngles, phiArrivalAngles);
% Create steering vector/matrix
e = steeringVector(xPos, yPos, zPos, f, c, thetaScanAngles, phiScanAngles);
% Create cross spectral matrix
R = crossSpectralMatrix(inputSignal);
% Calculate delay-and-sum steered response
S = steeredResponseDelayAndSum(R, e, elementWeights);
%Normalise spectrum
spectrumNormalized = abs(S)/max(abs(S));
%Convert to decibel
spectrumLog = 10*log10(spectrumNormalized);
%Plot array
fig1 = figure;
fig1.Color = ‘w’;
ax = axes(‘Parent’, fig1);
scatter(ax, xPos, yPos, 20, ‘filled’)
axis(ax, ‘square’)
ax.XLim = [-1 1];
ax.YLim = [-1 1];
grid(ax, ‘on’)
title(ax, ‘Microphone positions’)
%Plot steered response with indicator lines
fig2 = figure;
fig2.Color = ‘w’;
ax = axes(‘Parent’, fig2);
plot(ax, thetaScanAngles, spectrumLog)
grid(ax, ‘on’)
ax.XLim = [thetaScanAngles(1) thetaScanAngles(end)];
for j=1:numel(thetaArrivalAngles)
indx = find(thetaScanAngles >= thetaArrivalAngles(j), 1);
line(ax, [thetaScanAngles(indx) thetaScanAngles(indx)], ax.YLim,’LineWidth’, 1, ‘Color’, ‘r’, ‘LineStyle’, ‘–‘);
end
xlabel(ax, ‘theta’)
ylabel(ax, ‘dB’) digital signal processing MATLAB Answers — New Questions
SVPWM abnormal current under inductive load
I desing three phase inverter with SVPWM with matlab&simulink 2024a
It works perfectly under resistive load.
When I add 450VAR inductive load to 450W resistive load at 0,02 second, phase a and b currents shift up and phase c current shift down. why?
All loads is balanced. Why does current behavior like that? How can ı solve it?I desing three phase inverter with SVPWM with matlab&simulink 2024a
It works perfectly under resistive load.
When I add 450VAR inductive load to 450W resistive load at 0,02 second, phase a and b currents shift up and phase c current shift down. why?
All loads is balanced. Why does current behavior like that? How can ı solve it? I desing three phase inverter with SVPWM with matlab&simulink 2024a
It works perfectly under resistive load.
When I add 450VAR inductive load to 450W resistive load at 0,02 second, phase a and b currents shift up and phase c current shift down. why?
All loads is balanced. Why does current behavior like that? How can ı solve it? inductive load, svpwm, load MATLAB Answers — New Questions