Category: Matlab
Category Archives: Matlab
Error Using horzcat in MATLAB
How to correct the following error in MATLAB? The received image is just a block of static.
clc;
clear all;
% Load the lenna image
lenna = imread(‘lenna.png’);
% Convert image to grayscale
lenna_gray = rgb2gray(lenna);
% Convert pixel values to bits
lenna_bits = reshape(de2bi(lenna_gray), [], 1);
% BPSK modulation
Eb_No_low = 0; % Low SNR
Eb_No_high = 4; % High SNR
SNR_low = 10^(Eb_No_low/10);
SNR_high = 10^(Eb_No_high/10);
% Transmit and receive at low SNR
received_low = awgn(double(lenna_bits), SNR_low, ‘measured’);
% Demodulation
decoded_low = received_low < 0;
% Reshape decoded bits to original image size
decoded_image_low = reshape(decoded_low, size(lenna_gray, 1), []);
% Plot original and received image at low SNR
figure;
subplot(1,2,1); imshow(lenna_gray); title(‘Original Image’);
subplot(1,2,2); imshow(decoded_image_low); title(‘Received Image (0 dB SNR)’);
% Transmit and receive at high SNR
received_high = awgn(double(lenna_bits), SNR_high, ‘measured’);
% Demodulation
decoded_high = received_high < 0;
% Reshape decoded bits to original image size
decoded_image_high = reshape(decoded_high, size(lenna_gray, 1), []);
% Plot original and received image at high SNR
figure;
subplot(1,2,1); imshow(lenna_gray); title(‘Original Image’);
subplot(1,2,2); imshow(decoded_image_high); title(‘Received Image (4 dB SNR)’);
% Linear error detection code
% Example: Hamming (7,4) code
parityMatrix = [1 1 1 0 1 0 0; 1 1 0 1 0 1 0; 1 0 1 1 0 0 1];
generatorMatrix = [eye(4) parityMatrix’];
% Encode the data
encoded_data = mod(lenna_bits * generatorMatrix, 2);
% Add noise for linear error detection code
received_data = awgn(double(encoded_data), Eb_No_low, ‘measured’);
% Syndrome lookup table for error detection
syndrome_table = syndtable(parityMatrix);
% Decoding with error detection
decoded_data = zeros(size(encoded_data));
errors = zeros(size(encoded_data, 1), 1);
for i = 1:size(encoded_data, 1)
syndrome = mod(received_data(i, 🙂 * parityMatrix’, 2);
if sum(syndrome) ~= 0 % Error detected
errors(i) = 1;
else
decoded_data(i, 🙂 = received_data(i, :);
end
end
% Count number of retransmission requests at different SNRs
SNRs = [0, 2, 4, 6, 8, 10];
retransmissions = zeros(size(SNRs));
for i = 1:length(SNRs)
SNR = 10^(SNRs(i)/10);
received_data = awgn(encoded_data, SNR, ‘measured’);
errors = zeros(size(encoded_data, 1), 1);
for j = 1:size(encoded_data, 1)
syndrome = mod(received_data(j, 🙂 * parityMatrix’, 2);
if sum(syndrome) ~= 0 % Error detected
errors(j) = 1;
retransmissions(i) = retransmissions(i) + 1;
end
end
end
% Plot number of retransmissions against SNR values
figure;
plot(SNRs, retransmissions, ‘-o’);
xlabel(‘SNR (dB)’);
ylabel(‘Number of Retransmissions’);
title(‘Number of Retransmissions vs SNR’);
% Error correction code
% Example: Reed-Solomon code
n = 255;
k = 223;
t = 16;
rs_encoder = comm.RSEncoder(n, k);
rs_decoder = comm.RSDecoder(n, k);
% Encode data
encoded_rs = step(rs_encoder, double(lenna_bits));
% Add noise for Reed-Solomon code
received_rs_low = awgn(double(encoded_rs), Eb_No_low, ‘measured’);
received_rs_high = awgn(double(encoded_rs), Eb_No_high, ‘measured’);
% Decode received data
decoded_rs_low = step(rs_decoder, received_rs_low);
decoded_rs_high = step(rs_decoder, received_rs_high);
% Reshape decoded bits to original image size
decoded_image_rs_low = reshape(decoded_rs_low, size(lenna_gray));
decoded_image_rs_high = reshape(decoded_rs_high, size(lenna_gray));
% Plot original and received images with error correction
figure;
subplot(1,2,1); imshow(decoded_image_low); title(‘Received Image (0 dB SNR, No Error Correction)’);
subplot(1,2,2); imshow(decoded_image_rs_low); title(‘Received Image (0 dB SNR, Error Correction)’);
figure;
subplot(1,2,1); imshow(decoded_image_high); title(‘Received Image (4 dB SNR, No Error Correction)’);
subplot(1,2,2); imshow(decoded_image_rs_high); title(‘Received Image (4 dB SNR, Error Correction)’);
Error using horzcat
Dimensions of arrays being concatenated are not consistent.
Error in Computerassignmentfinal (line 50)
generatorMatrix = [eye(4) parityMatrix’];How to correct the following error in MATLAB? The received image is just a block of static.
clc;
clear all;
% Load the lenna image
lenna = imread(‘lenna.png’);
% Convert image to grayscale
lenna_gray = rgb2gray(lenna);
% Convert pixel values to bits
lenna_bits = reshape(de2bi(lenna_gray), [], 1);
% BPSK modulation
Eb_No_low = 0; % Low SNR
Eb_No_high = 4; % High SNR
SNR_low = 10^(Eb_No_low/10);
SNR_high = 10^(Eb_No_high/10);
% Transmit and receive at low SNR
received_low = awgn(double(lenna_bits), SNR_low, ‘measured’);
% Demodulation
decoded_low = received_low < 0;
% Reshape decoded bits to original image size
decoded_image_low = reshape(decoded_low, size(lenna_gray, 1), []);
% Plot original and received image at low SNR
figure;
subplot(1,2,1); imshow(lenna_gray); title(‘Original Image’);
subplot(1,2,2); imshow(decoded_image_low); title(‘Received Image (0 dB SNR)’);
% Transmit and receive at high SNR
received_high = awgn(double(lenna_bits), SNR_high, ‘measured’);
% Demodulation
decoded_high = received_high < 0;
% Reshape decoded bits to original image size
decoded_image_high = reshape(decoded_high, size(lenna_gray, 1), []);
% Plot original and received image at high SNR
figure;
subplot(1,2,1); imshow(lenna_gray); title(‘Original Image’);
subplot(1,2,2); imshow(decoded_image_high); title(‘Received Image (4 dB SNR)’);
% Linear error detection code
% Example: Hamming (7,4) code
parityMatrix = [1 1 1 0 1 0 0; 1 1 0 1 0 1 0; 1 0 1 1 0 0 1];
generatorMatrix = [eye(4) parityMatrix’];
% Encode the data
encoded_data = mod(lenna_bits * generatorMatrix, 2);
% Add noise for linear error detection code
received_data = awgn(double(encoded_data), Eb_No_low, ‘measured’);
% Syndrome lookup table for error detection
syndrome_table = syndtable(parityMatrix);
% Decoding with error detection
decoded_data = zeros(size(encoded_data));
errors = zeros(size(encoded_data, 1), 1);
for i = 1:size(encoded_data, 1)
syndrome = mod(received_data(i, 🙂 * parityMatrix’, 2);
if sum(syndrome) ~= 0 % Error detected
errors(i) = 1;
else
decoded_data(i, 🙂 = received_data(i, :);
end
end
% Count number of retransmission requests at different SNRs
SNRs = [0, 2, 4, 6, 8, 10];
retransmissions = zeros(size(SNRs));
for i = 1:length(SNRs)
SNR = 10^(SNRs(i)/10);
received_data = awgn(encoded_data, SNR, ‘measured’);
errors = zeros(size(encoded_data, 1), 1);
for j = 1:size(encoded_data, 1)
syndrome = mod(received_data(j, 🙂 * parityMatrix’, 2);
if sum(syndrome) ~= 0 % Error detected
errors(j) = 1;
retransmissions(i) = retransmissions(i) + 1;
end
end
end
% Plot number of retransmissions against SNR values
figure;
plot(SNRs, retransmissions, ‘-o’);
xlabel(‘SNR (dB)’);
ylabel(‘Number of Retransmissions’);
title(‘Number of Retransmissions vs SNR’);
% Error correction code
% Example: Reed-Solomon code
n = 255;
k = 223;
t = 16;
rs_encoder = comm.RSEncoder(n, k);
rs_decoder = comm.RSDecoder(n, k);
% Encode data
encoded_rs = step(rs_encoder, double(lenna_bits));
% Add noise for Reed-Solomon code
received_rs_low = awgn(double(encoded_rs), Eb_No_low, ‘measured’);
received_rs_high = awgn(double(encoded_rs), Eb_No_high, ‘measured’);
% Decode received data
decoded_rs_low = step(rs_decoder, received_rs_low);
decoded_rs_high = step(rs_decoder, received_rs_high);
% Reshape decoded bits to original image size
decoded_image_rs_low = reshape(decoded_rs_low, size(lenna_gray));
decoded_image_rs_high = reshape(decoded_rs_high, size(lenna_gray));
% Plot original and received images with error correction
figure;
subplot(1,2,1); imshow(decoded_image_low); title(‘Received Image (0 dB SNR, No Error Correction)’);
subplot(1,2,2); imshow(decoded_image_rs_low); title(‘Received Image (0 dB SNR, Error Correction)’);
figure;
subplot(1,2,1); imshow(decoded_image_high); title(‘Received Image (4 dB SNR, No Error Correction)’);
subplot(1,2,2); imshow(decoded_image_rs_high); title(‘Received Image (4 dB SNR, Error Correction)’);
Error using horzcat
Dimensions of arrays being concatenated are not consistent.
Error in Computerassignmentfinal (line 50)
generatorMatrix = [eye(4) parityMatrix’]; How to correct the following error in MATLAB? The received image is just a block of static.
clc;
clear all;
% Load the lenna image
lenna = imread(‘lenna.png’);
% Convert image to grayscale
lenna_gray = rgb2gray(lenna);
% Convert pixel values to bits
lenna_bits = reshape(de2bi(lenna_gray), [], 1);
% BPSK modulation
Eb_No_low = 0; % Low SNR
Eb_No_high = 4; % High SNR
SNR_low = 10^(Eb_No_low/10);
SNR_high = 10^(Eb_No_high/10);
% Transmit and receive at low SNR
received_low = awgn(double(lenna_bits), SNR_low, ‘measured’);
% Demodulation
decoded_low = received_low < 0;
% Reshape decoded bits to original image size
decoded_image_low = reshape(decoded_low, size(lenna_gray, 1), []);
% Plot original and received image at low SNR
figure;
subplot(1,2,1); imshow(lenna_gray); title(‘Original Image’);
subplot(1,2,2); imshow(decoded_image_low); title(‘Received Image (0 dB SNR)’);
% Transmit and receive at high SNR
received_high = awgn(double(lenna_bits), SNR_high, ‘measured’);
% Demodulation
decoded_high = received_high < 0;
% Reshape decoded bits to original image size
decoded_image_high = reshape(decoded_high, size(lenna_gray, 1), []);
% Plot original and received image at high SNR
figure;
subplot(1,2,1); imshow(lenna_gray); title(‘Original Image’);
subplot(1,2,2); imshow(decoded_image_high); title(‘Received Image (4 dB SNR)’);
% Linear error detection code
% Example: Hamming (7,4) code
parityMatrix = [1 1 1 0 1 0 0; 1 1 0 1 0 1 0; 1 0 1 1 0 0 1];
generatorMatrix = [eye(4) parityMatrix’];
% Encode the data
encoded_data = mod(lenna_bits * generatorMatrix, 2);
% Add noise for linear error detection code
received_data = awgn(double(encoded_data), Eb_No_low, ‘measured’);
% Syndrome lookup table for error detection
syndrome_table = syndtable(parityMatrix);
% Decoding with error detection
decoded_data = zeros(size(encoded_data));
errors = zeros(size(encoded_data, 1), 1);
for i = 1:size(encoded_data, 1)
syndrome = mod(received_data(i, 🙂 * parityMatrix’, 2);
if sum(syndrome) ~= 0 % Error detected
errors(i) = 1;
else
decoded_data(i, 🙂 = received_data(i, :);
end
end
% Count number of retransmission requests at different SNRs
SNRs = [0, 2, 4, 6, 8, 10];
retransmissions = zeros(size(SNRs));
for i = 1:length(SNRs)
SNR = 10^(SNRs(i)/10);
received_data = awgn(encoded_data, SNR, ‘measured’);
errors = zeros(size(encoded_data, 1), 1);
for j = 1:size(encoded_data, 1)
syndrome = mod(received_data(j, 🙂 * parityMatrix’, 2);
if sum(syndrome) ~= 0 % Error detected
errors(j) = 1;
retransmissions(i) = retransmissions(i) + 1;
end
end
end
% Plot number of retransmissions against SNR values
figure;
plot(SNRs, retransmissions, ‘-o’);
xlabel(‘SNR (dB)’);
ylabel(‘Number of Retransmissions’);
title(‘Number of Retransmissions vs SNR’);
% Error correction code
% Example: Reed-Solomon code
n = 255;
k = 223;
t = 16;
rs_encoder = comm.RSEncoder(n, k);
rs_decoder = comm.RSDecoder(n, k);
% Encode data
encoded_rs = step(rs_encoder, double(lenna_bits));
% Add noise for Reed-Solomon code
received_rs_low = awgn(double(encoded_rs), Eb_No_low, ‘measured’);
received_rs_high = awgn(double(encoded_rs), Eb_No_high, ‘measured’);
% Decode received data
decoded_rs_low = step(rs_decoder, received_rs_low);
decoded_rs_high = step(rs_decoder, received_rs_high);
% Reshape decoded bits to original image size
decoded_image_rs_low = reshape(decoded_rs_low, size(lenna_gray));
decoded_image_rs_high = reshape(decoded_rs_high, size(lenna_gray));
% Plot original and received images with error correction
figure;
subplot(1,2,1); imshow(decoded_image_low); title(‘Received Image (0 dB SNR, No Error Correction)’);
subplot(1,2,2); imshow(decoded_image_rs_low); title(‘Received Image (0 dB SNR, Error Correction)’);
figure;
subplot(1,2,1); imshow(decoded_image_high); title(‘Received Image (4 dB SNR, No Error Correction)’);
subplot(1,2,2); imshow(decoded_image_rs_high); title(‘Received Image (4 dB SNR, Error Correction)’);
Error using horzcat
Dimensions of arrays being concatenated are not consistent.
Error in Computerassignmentfinal (line 50)
generatorMatrix = [eye(4) parityMatrix’]; horzcat error MATLAB Answers — New Questions
My pie chart wont show up
This is my main file.
clear; clc;
% Main script
disp(‘Welcome to Recipe Cost Calculator’);
choice = menu(‘Select an option:’, ‘Calculate Recipe Cost’, ‘Exit’); %%this creates a button where it says calculate the recipe cost or to exit out of the program
while choice ~= 2 %%this line just means that while the user doesn’t chose the 2nd option, which is exit(laue of 2), then the program will continue to run
switch choice %%I decided to insert a switch stament for 2 different senarios. either case1 or case 2
case 1
disp(‘Enter ingredients for the recipe:’); %% this just displys this statment. where is where the user can input that the ingridient is
[ingredients, quantities, prices] = getRecipeInput(); %this getRecipeInput();is the 3 out pts and ive assigned each what they are
totalCost = calculateRecipeCost(ingredients, quantities, prices); %% this clalculates the total cost based off of the ingridients, how many ingridients and the price of the ingridients
disp([‘Total cost of the recipe: $’, num2str(totalCost)]); %%this displays the total cost. Instead of just giving the numerical value the user has to know that this is the total cost of all the ingidients listed.
plotCostBreakdown(ingredients, quantities, prices); %% this genetrates a pie chart of the ingidients quantities and cost
case 2 %% if the user presses option 2 then the program exits
disp(‘Exiting…’); %this displays that the program with exit
return;
end
choice = menu(‘Select an option:’, ‘Calculate Recipe Cost’, ‘Exit’); %%then it loops back and the user can chose either iption 1 or 2 again
end
The I have 3 seperate function files.
function file 1 –
function totalCost = calculateRecipeCost(ingredients, quantities, prices) % this calculates the total cost
totalCost = sum(quantities .* prices); %%This multiplies each ingridinent cost and then sums up the prices together
%This function calculates the total cost of a recipe based on the
% provided ingredients, quantities, and prices.
end
function file 2 –
%UNTITLED4 Summary of this function goes here
% Detailed explanation goes here
function [ingredients, quantities, prices] = getRecipeInput()
ingredients = {}; %these have empty arrays so that the user inputs the price it can show
quantities = [];%these have empty arrays so that the user inputs the price it can show
prices = [];%these have empty arrays so that the user inputs the price it can show
while true %white this statment is true
ingredient = input(‘Enter ingredient name (or type "done" to finish): ‘, ‘s’); %% this is so that the user inputs the name of the ingidient
if strcmp(ingredient, ‘done’) %% this is so that when the user is done inputing ingredients, quantities, and price, the user can input done and it will calculate the total cost
break; % then it breaks while the loop
end
quantity = input(‘Enter quantity: ‘); % the user inputs quantity of the ingidient
price = input(‘Enter price per unit: ‘); % the user inputs the price
ingredients = [ingredients, ingredient]; %% these put the ingridients in an array with the quanitities and price of each ingridient
quantities = [quantities, quantity];
prices = [prices, price];
end
end
function file 3 –
%UNTITLED5 Summary of this function goes here
% Pie chart of cost breakdown
% Define function to plot cost breakdown
function costBreakdown(ingredients, quantities, prices)
% Generate pie chart
figure;
pie(prices .* quantities, ingredients);
title(‘Cost Breakdown’);
% Add legend and labels
legend(ingredients, ‘Location’, ‘BestOutside’);
ylabel(‘Cost’);
end
Please help me!!!This is my main file.
clear; clc;
% Main script
disp(‘Welcome to Recipe Cost Calculator’);
choice = menu(‘Select an option:’, ‘Calculate Recipe Cost’, ‘Exit’); %%this creates a button where it says calculate the recipe cost or to exit out of the program
while choice ~= 2 %%this line just means that while the user doesn’t chose the 2nd option, which is exit(laue of 2), then the program will continue to run
switch choice %%I decided to insert a switch stament for 2 different senarios. either case1 or case 2
case 1
disp(‘Enter ingredients for the recipe:’); %% this just displys this statment. where is where the user can input that the ingridient is
[ingredients, quantities, prices] = getRecipeInput(); %this getRecipeInput();is the 3 out pts and ive assigned each what they are
totalCost = calculateRecipeCost(ingredients, quantities, prices); %% this clalculates the total cost based off of the ingridients, how many ingridients and the price of the ingridients
disp([‘Total cost of the recipe: $’, num2str(totalCost)]); %%this displays the total cost. Instead of just giving the numerical value the user has to know that this is the total cost of all the ingidients listed.
plotCostBreakdown(ingredients, quantities, prices); %% this genetrates a pie chart of the ingidients quantities and cost
case 2 %% if the user presses option 2 then the program exits
disp(‘Exiting…’); %this displays that the program with exit
return;
end
choice = menu(‘Select an option:’, ‘Calculate Recipe Cost’, ‘Exit’); %%then it loops back and the user can chose either iption 1 or 2 again
end
The I have 3 seperate function files.
function file 1 –
function totalCost = calculateRecipeCost(ingredients, quantities, prices) % this calculates the total cost
totalCost = sum(quantities .* prices); %%This multiplies each ingridinent cost and then sums up the prices together
%This function calculates the total cost of a recipe based on the
% provided ingredients, quantities, and prices.
end
function file 2 –
%UNTITLED4 Summary of this function goes here
% Detailed explanation goes here
function [ingredients, quantities, prices] = getRecipeInput()
ingredients = {}; %these have empty arrays so that the user inputs the price it can show
quantities = [];%these have empty arrays so that the user inputs the price it can show
prices = [];%these have empty arrays so that the user inputs the price it can show
while true %white this statment is true
ingredient = input(‘Enter ingredient name (or type "done" to finish): ‘, ‘s’); %% this is so that the user inputs the name of the ingidient
if strcmp(ingredient, ‘done’) %% this is so that when the user is done inputing ingredients, quantities, and price, the user can input done and it will calculate the total cost
break; % then it breaks while the loop
end
quantity = input(‘Enter quantity: ‘); % the user inputs quantity of the ingidient
price = input(‘Enter price per unit: ‘); % the user inputs the price
ingredients = [ingredients, ingredient]; %% these put the ingridients in an array with the quanitities and price of each ingridient
quantities = [quantities, quantity];
prices = [prices, price];
end
end
function file 3 –
%UNTITLED5 Summary of this function goes here
% Pie chart of cost breakdown
% Define function to plot cost breakdown
function costBreakdown(ingredients, quantities, prices)
% Generate pie chart
figure;
pie(prices .* quantities, ingredients);
title(‘Cost Breakdown’);
% Add legend and labels
legend(ingredients, ‘Location’, ‘BestOutside’);
ylabel(‘Cost’);
end
Please help me!!! This is my main file.
clear; clc;
% Main script
disp(‘Welcome to Recipe Cost Calculator’);
choice = menu(‘Select an option:’, ‘Calculate Recipe Cost’, ‘Exit’); %%this creates a button where it says calculate the recipe cost or to exit out of the program
while choice ~= 2 %%this line just means that while the user doesn’t chose the 2nd option, which is exit(laue of 2), then the program will continue to run
switch choice %%I decided to insert a switch stament for 2 different senarios. either case1 or case 2
case 1
disp(‘Enter ingredients for the recipe:’); %% this just displys this statment. where is where the user can input that the ingridient is
[ingredients, quantities, prices] = getRecipeInput(); %this getRecipeInput();is the 3 out pts and ive assigned each what they are
totalCost = calculateRecipeCost(ingredients, quantities, prices); %% this clalculates the total cost based off of the ingridients, how many ingridients and the price of the ingridients
disp([‘Total cost of the recipe: $’, num2str(totalCost)]); %%this displays the total cost. Instead of just giving the numerical value the user has to know that this is the total cost of all the ingidients listed.
plotCostBreakdown(ingredients, quantities, prices); %% this genetrates a pie chart of the ingidients quantities and cost
case 2 %% if the user presses option 2 then the program exits
disp(‘Exiting…’); %this displays that the program with exit
return;
end
choice = menu(‘Select an option:’, ‘Calculate Recipe Cost’, ‘Exit’); %%then it loops back and the user can chose either iption 1 or 2 again
end
The I have 3 seperate function files.
function file 1 –
function totalCost = calculateRecipeCost(ingredients, quantities, prices) % this calculates the total cost
totalCost = sum(quantities .* prices); %%This multiplies each ingridinent cost and then sums up the prices together
%This function calculates the total cost of a recipe based on the
% provided ingredients, quantities, and prices.
end
function file 2 –
%UNTITLED4 Summary of this function goes here
% Detailed explanation goes here
function [ingredients, quantities, prices] = getRecipeInput()
ingredients = {}; %these have empty arrays so that the user inputs the price it can show
quantities = [];%these have empty arrays so that the user inputs the price it can show
prices = [];%these have empty arrays so that the user inputs the price it can show
while true %white this statment is true
ingredient = input(‘Enter ingredient name (or type "done" to finish): ‘, ‘s’); %% this is so that the user inputs the name of the ingidient
if strcmp(ingredient, ‘done’) %% this is so that when the user is done inputing ingredients, quantities, and price, the user can input done and it will calculate the total cost
break; % then it breaks while the loop
end
quantity = input(‘Enter quantity: ‘); % the user inputs quantity of the ingidient
price = input(‘Enter price per unit: ‘); % the user inputs the price
ingredients = [ingredients, ingredient]; %% these put the ingridients in an array with the quanitities and price of each ingridient
quantities = [quantities, quantity];
prices = [prices, price];
end
end
function file 3 –
%UNTITLED5 Summary of this function goes here
% Pie chart of cost breakdown
% Define function to plot cost breakdown
function costBreakdown(ingredients, quantities, prices)
% Generate pie chart
figure;
pie(prices .* quantities, ingredients);
title(‘Cost Breakdown’);
% Add legend and labels
legend(ingredients, ‘Location’, ‘BestOutside’);
ylabel(‘Cost’);
end
Please help me!!! help, pie chart, matlab code, matlab, i need help, array, chart, graph MATLAB Answers — New Questions
An error occurred while running the simulation and the simulation was terminated
I’m trying to model a MicroGrid protection circuit with a Wind Turbine Induction Generator and an ACDCAC converter. Whenever I run the simulation I get the following error:
An error occurred while running the simulation and the simulation was terminated
Caused by:
Block ‘windmillacdcac10x2810x29/Wind Turbine Induction Generator (Phasor Type)/Asynchronous Machine/Electrical model/Asynchronous Machine State-space model/Electromagnetic Torque/Mult1’ outputs ‘Inf’ for element 1 of output port 1 at major time step 6.8E-05
Before this the simulation error asked me to change the Discrete Solver parameter of the Asynchronous Machine Block inside the Wind Turbine Indcution generator model from Forward Euler to Trapezoidal. I did that and the above error is the result. I’ve attached photos of the main circuit as well as the Wind turbine induction generator block and the Multi1 block. Hope somebody can help me fix this.I’m trying to model a MicroGrid protection circuit with a Wind Turbine Induction Generator and an ACDCAC converter. Whenever I run the simulation I get the following error:
An error occurred while running the simulation and the simulation was terminated
Caused by:
Block ‘windmillacdcac10x2810x29/Wind Turbine Induction Generator (Phasor Type)/Asynchronous Machine/Electrical model/Asynchronous Machine State-space model/Electromagnetic Torque/Mult1’ outputs ‘Inf’ for element 1 of output port 1 at major time step 6.8E-05
Before this the simulation error asked me to change the Discrete Solver parameter of the Asynchronous Machine Block inside the Wind Turbine Indcution generator model from Forward Euler to Trapezoidal. I did that and the above error is the result. I’ve attached photos of the main circuit as well as the Wind turbine induction generator block and the Multi1 block. Hope somebody can help me fix this. I’m trying to model a MicroGrid protection circuit with a Wind Turbine Induction Generator and an ACDCAC converter. Whenever I run the simulation I get the following error:
An error occurred while running the simulation and the simulation was terminated
Caused by:
Block ‘windmillacdcac10x2810x29/Wind Turbine Induction Generator (Phasor Type)/Asynchronous Machine/Electrical model/Asynchronous Machine State-space model/Electromagnetic Torque/Mult1’ outputs ‘Inf’ for element 1 of output port 1 at major time step 6.8E-05
Before this the simulation error asked me to change the Discrete Solver parameter of the Asynchronous Machine Block inside the Wind Turbine Indcution generator model from Forward Euler to Trapezoidal. I did that and the above error is the result. I’ve attached photos of the main circuit as well as the Wind turbine induction generator block and the Multi1 block. Hope somebody can help me fix this. optimization, simpowersystems, cigre, power_electronics_control, simulink, simulation, simscape MATLAB Answers — New Questions
Why do I get an error using estimate for an msVAR model?
Hi,
I want use "estimate" to fit the parameters of an msVAR model but I get the error "number of rows in presample array ‘Y0’ must be at least 1".
I don’t know why I keep getting this error, since I am closelye following one of MATLABs examples (Analyze US Unemployment Rate Using Markov-Switching Model).
Mdl is the model to be estimated, Mdl0 contains the initial values. I don’t see what I am missing here.
EstMdl = estimate(Mdl,Mdl0,Data);Hi,
I want use "estimate" to fit the parameters of an msVAR model but I get the error "number of rows in presample array ‘Y0’ must be at least 1".
I don’t know why I keep getting this error, since I am closelye following one of MATLABs examples (Analyze US Unemployment Rate Using Markov-Switching Model).
Mdl is the model to be estimated, Mdl0 contains the initial values. I don’t see what I am missing here.
EstMdl = estimate(Mdl,Mdl0,Data); Hi,
I want use "estimate" to fit the parameters of an msVAR model but I get the error "number of rows in presample array ‘Y0’ must be at least 1".
I don’t know why I keep getting this error, since I am closelye following one of MATLABs examples (Analyze US Unemployment Rate Using Markov-Switching Model).
Mdl is the model to be estimated, Mdl0 contains the initial values. I don’t see what I am missing here.
EstMdl = estimate(Mdl,Mdl0,Data); estimate, msvar, error MATLAB Answers — New Questions
Why do I get the error “MATLAB Web App Server files not found. Verify that MATLAB Runtime appears before any installed version of MATLAB” while starting Web App Server?
I have installed Web App Server after following the instructions given on documentation.
When I try to start Web App Server server executable, I receive the error –
"MATLAB Web App Server files not found. Verify that MATLAB Runtime appears before any installed version of MATLAB".
<<http://www.mathworks.com/matlabcentral/answers/uploaded_files/112884/88ddf49fccf5311236a46767ee34f911.jpeg>>
How to fix this?I have installed Web App Server after following the instructions given on documentation.
When I try to start Web App Server server executable, I receive the error –
"MATLAB Web App Server files not found. Verify that MATLAB Runtime appears before any installed version of MATLAB".
<<http://www.mathworks.com/matlabcentral/answers/uploaded_files/112884/88ddf49fccf5311236a46767ee34f911.jpeg>>
How to fix this? I have installed Web App Server after following the instructions given on documentation.
When I try to start Web App Server server executable, I receive the error –
"MATLAB Web App Server files not found. Verify that MATLAB Runtime appears before any installed version of MATLAB".
<<http://www.mathworks.com/matlabcentral/answers/uploaded_files/112884/88ddf49fccf5311236a46767ee34f911.jpeg>>
How to fix this? webapp, file, not, found, path MATLAB Answers — New Questions
How do I utilize a function with multiple outputs within another function?
I’m ranking values within columns of an array (descending), where the final output is an array with each value’s rank in the same position as the original value. I’m able to do this with multiple lines of code as follows:
[~,DR] = sort(vals,’descend’); % DR: index of values in descending order
[~,valsDRank] = sort(DR,’ascend’); % valsDRank: ranks in array position of original value
I’m curious how to accomplish this using a nested sort command in one line of code due to the multiple outputs of the sort function?
Thanks!I’m ranking values within columns of an array (descending), where the final output is an array with each value’s rank in the same position as the original value. I’m able to do this with multiple lines of code as follows:
[~,DR] = sort(vals,’descend’); % DR: index of values in descending order
[~,valsDRank] = sort(DR,’ascend’); % valsDRank: ranks in array position of original value
I’m curious how to accomplish this using a nested sort command in one line of code due to the multiple outputs of the sort function?
Thanks! I’m ranking values within columns of an array (descending), where the final output is an array with each value’s rank in the same position as the original value. I’m able to do this with multiple lines of code as follows:
[~,DR] = sort(vals,’descend’); % DR: index of values in descending order
[~,valsDRank] = sort(DR,’ascend’); % valsDRank: ranks in array position of original value
I’m curious how to accomplish this using a nested sort command in one line of code due to the multiple outputs of the sort function?
Thanks! value rank MATLAB Answers — New Questions
Identified linear system contribution of input is zero
Hello,
I identified a cont. 3rd order linear system using System Identification Toolbox:
y = Cx + Du + e
dx/dt = Ax + Bu + Ke
Upon inspecting the model (which looked decent to me) I see that the "D" value, which is the contribution of input to system output, is zero.
How can this be? The system describes a DC motor controlled by PWM commands (output is shaft position). Surely the commands sent to the motor should influence the position?
I get the following values:
% A weights (3×3 matrix)
A = [ …
0.0356, -3.4131, -14.9525;
-1.0591, 85.8128, 334.3098;
1.5729, -95.1123, -175.5517;
];
% B weights (3×1 vector)
B = [ …
-0.0019;
0.0403;
-0.0225;
];
% C weights (1×3 vector)
C = [ -5316.9, 24.87, 105.92 ];
% D weight (scalar)
D = 0;
% K weights (3×1 vector)
K = [ …
-0.0025;
-0.0582;
0.0984;
];
% Initial state
x0 = [ …
-0.0458;
0.0099;
-0.0139;
];Hello,
I identified a cont. 3rd order linear system using System Identification Toolbox:
y = Cx + Du + e
dx/dt = Ax + Bu + Ke
Upon inspecting the model (which looked decent to me) I see that the "D" value, which is the contribution of input to system output, is zero.
How can this be? The system describes a DC motor controlled by PWM commands (output is shaft position). Surely the commands sent to the motor should influence the position?
I get the following values:
% A weights (3×3 matrix)
A = [ …
0.0356, -3.4131, -14.9525;
-1.0591, 85.8128, 334.3098;
1.5729, -95.1123, -175.5517;
];
% B weights (3×1 vector)
B = [ …
-0.0019;
0.0403;
-0.0225;
];
% C weights (1×3 vector)
C = [ -5316.9, 24.87, 105.92 ];
% D weight (scalar)
D = 0;
% K weights (3×1 vector)
K = [ …
-0.0025;
-0.0582;
0.0984;
];
% Initial state
x0 = [ …
-0.0458;
0.0099;
-0.0139;
]; Hello,
I identified a cont. 3rd order linear system using System Identification Toolbox:
y = Cx + Du + e
dx/dt = Ax + Bu + Ke
Upon inspecting the model (which looked decent to me) I see that the "D" value, which is the contribution of input to system output, is zero.
How can this be? The system describes a DC motor controlled by PWM commands (output is shaft position). Surely the commands sent to the motor should influence the position?
I get the following values:
% A weights (3×3 matrix)
A = [ …
0.0356, -3.4131, -14.9525;
-1.0591, 85.8128, 334.3098;
1.5729, -95.1123, -175.5517;
];
% B weights (3×1 vector)
B = [ …
-0.0019;
0.0403;
-0.0225;
];
% C weights (1×3 vector)
C = [ -5316.9, 24.87, 105.92 ];
% D weight (scalar)
D = 0;
% K weights (3×1 vector)
K = [ …
-0.0025;
-0.0582;
0.0984;
];
% Initial state
x0 = [ …
-0.0458;
0.0099;
-0.0139;
]; system MATLAB Answers — New Questions
reproduces the audio signal after sampling!!!
One of the earliest extensions of this theorem was stated by Shannon himself in his 1949 paper, which says that if x(t)and its first (M – 1) derivatives are available, then uniformly spaced samples of these, taken at the reduced rate of M times, are sufficient to reconstruct x(t) . This result will be referred to as the derivative sampling theorem in this paper. I’m working with M=3 and having trouble designing a synthesis filter with an impulse response of the following form: sinc(t)^3; t.sinc(t)^3; t^2.sinc(t)^3. please help me?One of the earliest extensions of this theorem was stated by Shannon himself in his 1949 paper, which says that if x(t)and its first (M – 1) derivatives are available, then uniformly spaced samples of these, taken at the reduced rate of M times, are sufficient to reconstruct x(t) . This result will be referred to as the derivative sampling theorem in this paper. I’m working with M=3 and having trouble designing a synthesis filter with an impulse response of the following form: sinc(t)^3; t.sinc(t)^3; t^2.sinc(t)^3. please help me? One of the earliest extensions of this theorem was stated by Shannon himself in his 1949 paper, which says that if x(t)and its first (M – 1) derivatives are available, then uniformly spaced samples of these, taken at the reduced rate of M times, are sufficient to reconstruct x(t) . This result will be referred to as the derivative sampling theorem in this paper. I’m working with M=3 and having trouble designing a synthesis filter with an impulse response of the following form: sinc(t)^3; t.sinc(t)^3; t^2.sinc(t)^3. please help me? shannon, derivative sampling theorem, impulse response, sinc, audio singnal MATLAB Answers — New Questions
“arguments … end” syntax input argument validation module group supports C code generation?
The latest version of Matlab Coder does not seem to support the use of "arguments…end" module in functions. If so, I don’t have to specify the type and size of each input argument before calling the "codegen" function?
I hope this will be enhanced in future versions!
——-2022.3.24 update——–
try/catch shoud also support C code generation.The latest version of Matlab Coder does not seem to support the use of "arguments…end" module in functions. If so, I don’t have to specify the type and size of each input argument before calling the "codegen" function?
I hope this will be enhanced in future versions!
——-2022.3.24 update——–
try/catch shoud also support C code generation. The latest version of Matlab Coder does not seem to support the use of "arguments…end" module in functions. If so, I don’t have to specify the type and size of each input argument before calling the "codegen" function?
I hope this will be enhanced in future versions!
——-2022.3.24 update——–
try/catch shoud also support C code generation. matlab coder, arguments MATLAB Answers — New Questions
Extremely long delay when opening a Simulink model with UDP block (Instrument Control Toolbox)
Hi all,
I have the following problem: When I try to open a Simulink model with an UDP receive or send block (from the Instrument Control Toolbox) for the first time after starting Simulink, I have to wait over 30 minutes until the program show ready. After this first launch, I can work with the model without any problems. The problem still persists after reinstalling Matlab and Simulink. During the startup time, I can see in the task manager that Matlab is using 35 % of the CPU power. There are two processes from type "Java Chromium Embedded Framework (JCEF) Helper" and two from type "Matlab 2020a". I think it is a problem with the "Instrumental Control Toolbox" because I only have this problem when I use blocks from it.
Does someone else also have this problem and how can it be solved?
—————————————————————————————————–
MATLAB Version: 9.8.0.1323502 (R2020a)
Operating System: Microsoft Windows 10 Pro Version 10.0 (Build 18362)
Java Version: Java 1.8.0_202-b08 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
—————————————————————————————————–
Instrument Control Toolbox Version 4.2 (R2020a)Hi all,
I have the following problem: When I try to open a Simulink model with an UDP receive or send block (from the Instrument Control Toolbox) for the first time after starting Simulink, I have to wait over 30 minutes until the program show ready. After this first launch, I can work with the model without any problems. The problem still persists after reinstalling Matlab and Simulink. During the startup time, I can see in the task manager that Matlab is using 35 % of the CPU power. There are two processes from type "Java Chromium Embedded Framework (JCEF) Helper" and two from type "Matlab 2020a". I think it is a problem with the "Instrumental Control Toolbox" because I only have this problem when I use blocks from it.
Does someone else also have this problem and how can it be solved?
—————————————————————————————————–
MATLAB Version: 9.8.0.1323502 (R2020a)
Operating System: Microsoft Windows 10 Pro Version 10.0 (Build 18362)
Java Version: Java 1.8.0_202-b08 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
—————————————————————————————————–
Instrument Control Toolbox Version 4.2 (R2020a) Hi all,
I have the following problem: When I try to open a Simulink model with an UDP receive or send block (from the Instrument Control Toolbox) for the first time after starting Simulink, I have to wait over 30 minutes until the program show ready. After this first launch, I can work with the model without any problems. The problem still persists after reinstalling Matlab and Simulink. During the startup time, I can see in the task manager that Matlab is using 35 % of the CPU power. There are two processes from type "Java Chromium Embedded Framework (JCEF) Helper" and two from type "Matlab 2020a". I think it is a problem with the "Instrumental Control Toolbox" because I only have this problem when I use blocks from it.
Does someone else also have this problem and how can it be solved?
—————————————————————————————————–
MATLAB Version: 9.8.0.1323502 (R2020a)
Operating System: Microsoft Windows 10 Pro Version 10.0 (Build 18362)
Java Version: Java 1.8.0_202-b08 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
—————————————————————————————————–
Instrument Control Toolbox Version 4.2 (R2020a) instrument control toolbox, udp MATLAB Answers — New Questions
I cannot enable 3D view in the driving scenario designer app [It may be related to the Ubuntu system]
Post Content Post Content driving scenario designer MATLAB Answers — New Questions
Is MathWorks working on a dark mode for MATLAB similar to what Visual Studio offers?
Visual Studio’s dark mode changes the background color for all the toolbars and all over the UI. The most that can be obtained with MATLAB is to change the background color settings of text,editors and workspace windows. There are many tools that helps achieve this like Scott lowe’s version shared on community here Is MathWorks working on a dark mode to achieve complete UI dark mode unlike the patch work that is available now?Visual Studio’s dark mode changes the background color for all the toolbars and all over the UI. The most that can be obtained with MATLAB is to change the background color settings of text,editors and workspace windows. There are many tools that helps achieve this like Scott lowe’s version shared on community here Is MathWorks working on a dark mode to achieve complete UI dark mode unlike the patch work that is available now? Visual Studio’s dark mode changes the background color for all the toolbars and all over the UI. The most that can be obtained with MATLAB is to change the background color settings of text,editors and workspace windows. There are many tools that helps achieve this like Scott lowe’s version shared on community here Is MathWorks working on a dark mode to achieve complete UI dark mode unlike the patch work that is available now? MATLAB Answers — New Questions
Confidence levels for glmfit – glmval or fitglm using the Likelihood Ratio method
After several days and many hours of researching and googling, I am unable to determine how I could find confidence levels using the Likelihood Ratio for either glmfit – glmval or fitglm. I know it can be done in R, but I don’t see that capability in Matlab. Does it exist? Neither glmval nor coefCI appear to use or have options for using the Likelihood Ratio method. And paramci does not appear to work with a GeneralizedLinearModel object.
Thanks for any help you can provide.After several days and many hours of researching and googling, I am unable to determine how I could find confidence levels using the Likelihood Ratio for either glmfit – glmval or fitglm. I know it can be done in R, but I don’t see that capability in Matlab. Does it exist? Neither glmval nor coefCI appear to use or have options for using the Likelihood Ratio method. And paramci does not appear to work with a GeneralizedLinearModel object.
Thanks for any help you can provide. After several days and many hours of researching and googling, I am unable to determine how I could find confidence levels using the Likelihood Ratio for either glmfit – glmval or fitglm. I know it can be done in R, but I don’t see that capability in Matlab. Does it exist? Neither glmval nor coefCI appear to use or have options for using the Likelihood Ratio method. And paramci does not appear to work with a GeneralizedLinearModel object.
Thanks for any help you can provide. statistics, generalized linear model MATLAB Answers — New Questions
Error using mex ‘No supported compiler was found’ on Mac.
I am trying to run a c++ program in Matlab. To do this I am using mex. I have a mac.
I was trying to get my c++ files to run but that wasn’t working so to begin with I have been trying to use this example provided by MATLAB: https://uk.mathworks.com/help/matlab/matlab_external/build-an-executable-mex-file.html
Each time I run the command ‘mex timestwo.c’ I recieve the same error as when I was trying to get my own programme to run. The error says:
‘Warning: Xcode is installed, but its license has not been accepted. Run Xcode and accept its license agreement.
Error using mex
No supported compiler was found. For options, visit https://www.mathworks.com/support/compilers.’
This seems to be a very common problem and I have looked through all the guidance I can find but I am still recieving the same error. I have xcode 10.x and MATLAB 2019a and I have accepted the Xcode licence.
Thank you in advanceI am trying to run a c++ program in Matlab. To do this I am using mex. I have a mac.
I was trying to get my c++ files to run but that wasn’t working so to begin with I have been trying to use this example provided by MATLAB: https://uk.mathworks.com/help/matlab/matlab_external/build-an-executable-mex-file.html
Each time I run the command ‘mex timestwo.c’ I recieve the same error as when I was trying to get my own programme to run. The error says:
‘Warning: Xcode is installed, but its license has not been accepted. Run Xcode and accept its license agreement.
Error using mex
No supported compiler was found. For options, visit https://www.mathworks.com/support/compilers.’
This seems to be a very common problem and I have looked through all the guidance I can find but I am still recieving the same error. I have xcode 10.x and MATLAB 2019a and I have accepted the Xcode licence.
Thank you in advance I am trying to run a c++ program in Matlab. To do this I am using mex. I have a mac.
I was trying to get my c++ files to run but that wasn’t working so to begin with I have been trying to use this example provided by MATLAB: https://uk.mathworks.com/help/matlab/matlab_external/build-an-executable-mex-file.html
Each time I run the command ‘mex timestwo.c’ I recieve the same error as when I was trying to get my own programme to run. The error says:
‘Warning: Xcode is installed, but its license has not been accepted. Run Xcode and accept its license agreement.
Error using mex
No supported compiler was found. For options, visit https://www.mathworks.com/support/compilers.’
This seems to be a very common problem and I have looked through all the guidance I can find but I am still recieving the same error. I have xcode 10.x and MATLAB 2019a and I have accepted the Xcode licence.
Thank you in advance mex, mac, xcode, compiler MATLAB Answers — New Questions
Exporting a custom trained network to C#. MATLAB coder or ONNX?
I have a simple working trained custom network code that does a great job for me in classifying new data (arrays of 202 integers which represent some physical curves, which need to be classified to either ‘good’ or ‘bad’ curves).
I have used a starightforward patternnet(30) network.
Now I need to delpoy my prediction function into a C# project. I relized that matlab coder can’t handle loading and training networks, so I have to save my trained network via Matlab and then load it through C# and run there the predict function, which matlab coder will hopefully run.
For this reason I realized that I might need to use exportONNXNetwork, but it forces me to use other network types (and not patternnet) such as SeriesNework or dlnetwork, which I didnt succeed to manually build layers to produce them.
I have also tried to use both classification learner and deep network designer apps to generate networks code for me that would be exported to ONNX and would also mimic the success of my simple patternnet network, but each time they generate code that the exportONNXNetwork function doesn’t like, and produce errors like:
Error using nnet.internal.cnn.onnx.exportONNXNetwork>iValidateNetwork
First argument must be a SeriesNetwork, DAGNetwork, dlnetwork, or layerGraph.
My original code of the working patternnet is:
function [PredictedLabels,PredictedScores]=NeuralNetTLD(handles)
close all;
clear;
load(‘C:UsersuserDocumentsMATLABData filesGoodMAT_2024’);
load(‘C:UsersuserDocumentsMATLABData fileslabels_2024’);
load(‘C:UsersuserDocumentsMATLABData filesBadMAT_2024’);
goodId = (strcmp(labels,’GOOD’));
badId = (strcmp(labels,’BAD’));
Alllabels = [badId ; goodId];
DATA = [BadMAT1 GoodMAT1];
DATA=DATA(1:200,:);
DATA(201,:)=skewness(DATA,0);
DATA(202,:)=kurtosis(DATA,0);
net = patternnet(30);
net = configure(net,DATA,Alllabels);
net.divideParam.trainRatio = 60/100;
net.divideParam.valRatio = 20/100;
net.divideParam.testRatio = 20/100;
rng(1);
[net,tr] = train(net,DATA,Alllabels);
y = net(DATA);
predictions =net(trial);
figure;plot([1:202], trial(:,1:4)); figure; plot([1:202], trial(:,5));
PredictedScores= y(2,:)
PredictedLabels=labels;
end
I would love to hear a simple solution for this problem, as I think deploying a prediction function of a simple network to C# should be quite a common task to perform.
Thanks in advance,
GalI have a simple working trained custom network code that does a great job for me in classifying new data (arrays of 202 integers which represent some physical curves, which need to be classified to either ‘good’ or ‘bad’ curves).
I have used a starightforward patternnet(30) network.
Now I need to delpoy my prediction function into a C# project. I relized that matlab coder can’t handle loading and training networks, so I have to save my trained network via Matlab and then load it through C# and run there the predict function, which matlab coder will hopefully run.
For this reason I realized that I might need to use exportONNXNetwork, but it forces me to use other network types (and not patternnet) such as SeriesNework or dlnetwork, which I didnt succeed to manually build layers to produce them.
I have also tried to use both classification learner and deep network designer apps to generate networks code for me that would be exported to ONNX and would also mimic the success of my simple patternnet network, but each time they generate code that the exportONNXNetwork function doesn’t like, and produce errors like:
Error using nnet.internal.cnn.onnx.exportONNXNetwork>iValidateNetwork
First argument must be a SeriesNetwork, DAGNetwork, dlnetwork, or layerGraph.
My original code of the working patternnet is:
function [PredictedLabels,PredictedScores]=NeuralNetTLD(handles)
close all;
clear;
load(‘C:UsersuserDocumentsMATLABData filesGoodMAT_2024’);
load(‘C:UsersuserDocumentsMATLABData fileslabels_2024’);
load(‘C:UsersuserDocumentsMATLABData filesBadMAT_2024’);
goodId = (strcmp(labels,’GOOD’));
badId = (strcmp(labels,’BAD’));
Alllabels = [badId ; goodId];
DATA = [BadMAT1 GoodMAT1];
DATA=DATA(1:200,:);
DATA(201,:)=skewness(DATA,0);
DATA(202,:)=kurtosis(DATA,0);
net = patternnet(30);
net = configure(net,DATA,Alllabels);
net.divideParam.trainRatio = 60/100;
net.divideParam.valRatio = 20/100;
net.divideParam.testRatio = 20/100;
rng(1);
[net,tr] = train(net,DATA,Alllabels);
y = net(DATA);
predictions =net(trial);
figure;plot([1:202], trial(:,1:4)); figure; plot([1:202], trial(:,5));
PredictedScores= y(2,:)
PredictedLabels=labels;
end
I would love to hear a simple solution for this problem, as I think deploying a prediction function of a simple network to C# should be quite a common task to perform.
Thanks in advance,
Gal I have a simple working trained custom network code that does a great job for me in classifying new data (arrays of 202 integers which represent some physical curves, which need to be classified to either ‘good’ or ‘bad’ curves).
I have used a starightforward patternnet(30) network.
Now I need to delpoy my prediction function into a C# project. I relized that matlab coder can’t handle loading and training networks, so I have to save my trained network via Matlab and then load it through C# and run there the predict function, which matlab coder will hopefully run.
For this reason I realized that I might need to use exportONNXNetwork, but it forces me to use other network types (and not patternnet) such as SeriesNework or dlnetwork, which I didnt succeed to manually build layers to produce them.
I have also tried to use both classification learner and deep network designer apps to generate networks code for me that would be exported to ONNX and would also mimic the success of my simple patternnet network, but each time they generate code that the exportONNXNetwork function doesn’t like, and produce errors like:
Error using nnet.internal.cnn.onnx.exportONNXNetwork>iValidateNetwork
First argument must be a SeriesNetwork, DAGNetwork, dlnetwork, or layerGraph.
My original code of the working patternnet is:
function [PredictedLabels,PredictedScores]=NeuralNetTLD(handles)
close all;
clear;
load(‘C:UsersuserDocumentsMATLABData filesGoodMAT_2024’);
load(‘C:UsersuserDocumentsMATLABData fileslabels_2024’);
load(‘C:UsersuserDocumentsMATLABData filesBadMAT_2024’);
goodId = (strcmp(labels,’GOOD’));
badId = (strcmp(labels,’BAD’));
Alllabels = [badId ; goodId];
DATA = [BadMAT1 GoodMAT1];
DATA=DATA(1:200,:);
DATA(201,:)=skewness(DATA,0);
DATA(202,:)=kurtosis(DATA,0);
net = patternnet(30);
net = configure(net,DATA,Alllabels);
net.divideParam.trainRatio = 60/100;
net.divideParam.valRatio = 20/100;
net.divideParam.testRatio = 20/100;
rng(1);
[net,tr] = train(net,DATA,Alllabels);
y = net(DATA);
predictions =net(trial);
figure;plot([1:202], trial(:,1:4)); figure; plot([1:202], trial(:,5));
PredictedScores= y(2,:)
PredictedLabels=labels;
end
I would love to hear a simple solution for this problem, as I think deploying a prediction function of a simple network to C# should be quite a common task to perform.
Thanks in advance,
Gal c# deployment, neural network, matlab coder, onnx MATLAB Answers — New Questions
How can I create 3D seismic survey ?
Hi All,
I would like to create 3D seismic survey from 2D seismic lines?
I want to use Matlab not Seilab?
i will be thankful for your assistanceHi All,
I would like to create 3D seismic survey from 2D seismic lines?
I want to use Matlab not Seilab?
i will be thankful for your assistance Hi All,
I would like to create 3D seismic survey from 2D seismic lines?
I want to use Matlab not Seilab?
i will be thankful for your assistance seismic MATLAB Answers — New Questions
How can i set the dimension of the arrow in a quiver plot?
I want to set the arrows dimensions in my quiver plot to a fixed value. I’ve used this function
https://uk.mathworks.com/matlabcentral/answers/354324-how-to-make-the-quiver-arrow-head-size-fixed#answer_794194
but this dosent permit to scale the vectors. So using this i solve the problem of the arrow but i cant scale my vectors.
Thanks!I want to set the arrows dimensions in my quiver plot to a fixed value. I’ve used this function
https://uk.mathworks.com/matlabcentral/answers/354324-how-to-make-the-quiver-arrow-head-size-fixed#answer_794194
but this dosent permit to scale the vectors. So using this i solve the problem of the arrow but i cant scale my vectors.
Thanks! I want to set the arrows dimensions in my quiver plot to a fixed value. I’ve used this function
https://uk.mathworks.com/matlabcentral/answers/354324-how-to-make-the-quiver-arrow-head-size-fixed#answer_794194
but this dosent permit to scale the vectors. So using this i solve the problem of the arrow but i cant scale my vectors.
Thanks! quiver, scale, arrow MATLAB Answers — New Questions
how to scale arrows
I have this code for a vector field, the arrows keep getting crazier no mater what i do, can some one plese tell me how do i make them look nice and organized and same size
t1 = linspace(-1,500,10);
y1 = linspace(140,160,10);
[T,Y]=meshgrid(t1,y1);
DY=TribMod4(T,Y); DT=ones(size(DY));
scale = 1./sqrt(DT.^2+DY.^2);
p1=quiver(T,Y, 0.01.*DT, 0.001.*DY);
set(p1,’AutoScale’,’on’, ‘AutoScaleFactor’, 0.08)
axis([-5 500 140 160])
hold on
[t,y]=ode45(@TribMod4,[0:0.51:900],147.971);
plot(t,y,’r’)
ylabel(‘y’)
xlabel(‘time (t)’)
title(‘Direction field of function(2) with b=0.005’)
thanksI have this code for a vector field, the arrows keep getting crazier no mater what i do, can some one plese tell me how do i make them look nice and organized and same size
t1 = linspace(-1,500,10);
y1 = linspace(140,160,10);
[T,Y]=meshgrid(t1,y1);
DY=TribMod4(T,Y); DT=ones(size(DY));
scale = 1./sqrt(DT.^2+DY.^2);
p1=quiver(T,Y, 0.01.*DT, 0.001.*DY);
set(p1,’AutoScale’,’on’, ‘AutoScaleFactor’, 0.08)
axis([-5 500 140 160])
hold on
[t,y]=ode45(@TribMod4,[0:0.51:900],147.971);
plot(t,y,’r’)
ylabel(‘y’)
xlabel(‘time (t)’)
title(‘Direction field of function(2) with b=0.005’)
thanks I have this code for a vector field, the arrows keep getting crazier no mater what i do, can some one plese tell me how do i make them look nice and organized and same size
t1 = linspace(-1,500,10);
y1 = linspace(140,160,10);
[T,Y]=meshgrid(t1,y1);
DY=TribMod4(T,Y); DT=ones(size(DY));
scale = 1./sqrt(DT.^2+DY.^2);
p1=quiver(T,Y, 0.01.*DT, 0.001.*DY);
set(p1,’AutoScale’,’on’, ‘AutoScaleFactor’, 0.08)
axis([-5 500 140 160])
hold on
[t,y]=ode45(@TribMod4,[0:0.51:900],147.971);
plot(t,y,’r’)
ylabel(‘y’)
xlabel(‘time (t)’)
title(‘Direction field of function(2) with b=0.005’)
thanks scale, vector MATLAB Answers — New Questions
sorting non-exact x/y data into rows and columns, typewriter style
say I have the following two arrays:
x=[1.01 2.01 1.02 2.02];
y=[1.01 1.02 2.01 2.02];
sorting these rows using
xy = table(x’,y’)
[~, id] = sortrows(xy)
gives the answer of
id = [1;3;2;4];
I’m hoping to obtain the ‘typewriter’ answer of
id = [3, 4; 1, 2]
or something similar that tells me the third element of the table is the upper left, etc. The eventual goal is to combine elevation .tiff in the correct order to form a coherent dataset from northwest to southeast.
I feel like this should be a simple solution, but I’m delving into loops and logic and feel like I’m missing something easy.
Thanks in advance.say I have the following two arrays:
x=[1.01 2.01 1.02 2.02];
y=[1.01 1.02 2.01 2.02];
sorting these rows using
xy = table(x’,y’)
[~, id] = sortrows(xy)
gives the answer of
id = [1;3;2;4];
I’m hoping to obtain the ‘typewriter’ answer of
id = [3, 4; 1, 2]
or something similar that tells me the third element of the table is the upper left, etc. The eventual goal is to combine elevation .tiff in the correct order to form a coherent dataset from northwest to southeast.
I feel like this should be a simple solution, but I’m delving into loops and logic and feel like I’m missing something easy.
Thanks in advance. say I have the following two arrays:
x=[1.01 2.01 1.02 2.02];
y=[1.01 1.02 2.01 2.02];
sorting these rows using
xy = table(x’,y’)
[~, id] = sortrows(xy)
gives the answer of
id = [1;3;2;4];
I’m hoping to obtain the ‘typewriter’ answer of
id = [3, 4; 1, 2]
or something similar that tells me the third element of the table is the upper left, etc. The eventual goal is to combine elevation .tiff in the correct order to form a coherent dataset from northwest to southeast.
I feel like this should be a simple solution, but I’m delving into loops and logic and feel like I’m missing something easy.
Thanks in advance. sorting, array MATLAB Answers — New Questions
Placing circles on the ends of a vector
So I’m creating a movie model using data which describes a vector changing over time. I have the vector anchored at the origin and the head moves around according to the vector data. Because this is a bead-spring model, I want to graphically represent the beads by plotting circles at both ends of the vector. The problem I’m running into is that the bead that should be on the head of the vector is always offset by a certain amount. I can’t seem to figure out why it doesn’t have the same co-ords as the vector.
data = xlsread(‘C:UsersUserDocumentsMATLABData_Test.xlsx’,’Sheet1′);
t_s = data(:,1);
x_s = data(:,2);
y_s = data(:,3);
z_s = data(:,4);
d_s = size(t_s);
writerObj = VideoWriter(‘polymer.avi’);
open(writerObj);
for j = 1:d_s(1)
time = t_s(j);
x = x_s(j);
x1 = x*1000000;
y = y_s(j);
y1 = y*1000000;
z = z_s(j);
z1 = z*1000000;
h = quiver3(0, 0, 0, x1, y1, z1 );
set(h, ‘ShowArrowHead’, ‘off’);
axis([-5 15 -5 15 -5 15 3 5]);
title(‘it{Polymer Vibration}’,’FontSize’,16)
xlabel(‘x10^6′,’FontSize’,12);
ylabel(‘x10^6′,’FontSize’,12);
zlabel(‘x10^6′,’FontSize’,12);
timestamp_str = [‘t = ‘ num2str(time) ‘seconds’];
annotation(‘textbox’, [.05 .85 .1 .1],…
‘String’, timestamp_str);
hold all;
x2 = [0, x1];
y2 = [0, y1];
z2 = [0, z1];
scatter3( x2, y2, z2);
F(j) = getframe(gcf);
frame = getframe(gcf);
writeVideo(writerObj, frame);
clf;
disp([num2str(j) ‘ / ‘ num2str(d_s(1))])
end
movie(F);
close(writerObj);
An image of the problem I’m having:
<<http://i.imgur.com/JS1wp26.png>>So I’m creating a movie model using data which describes a vector changing over time. I have the vector anchored at the origin and the head moves around according to the vector data. Because this is a bead-spring model, I want to graphically represent the beads by plotting circles at both ends of the vector. The problem I’m running into is that the bead that should be on the head of the vector is always offset by a certain amount. I can’t seem to figure out why it doesn’t have the same co-ords as the vector.
data = xlsread(‘C:UsersUserDocumentsMATLABData_Test.xlsx’,’Sheet1′);
t_s = data(:,1);
x_s = data(:,2);
y_s = data(:,3);
z_s = data(:,4);
d_s = size(t_s);
writerObj = VideoWriter(‘polymer.avi’);
open(writerObj);
for j = 1:d_s(1)
time = t_s(j);
x = x_s(j);
x1 = x*1000000;
y = y_s(j);
y1 = y*1000000;
z = z_s(j);
z1 = z*1000000;
h = quiver3(0, 0, 0, x1, y1, z1 );
set(h, ‘ShowArrowHead’, ‘off’);
axis([-5 15 -5 15 -5 15 3 5]);
title(‘it{Polymer Vibration}’,’FontSize’,16)
xlabel(‘x10^6′,’FontSize’,12);
ylabel(‘x10^6′,’FontSize’,12);
zlabel(‘x10^6′,’FontSize’,12);
timestamp_str = [‘t = ‘ num2str(time) ‘seconds’];
annotation(‘textbox’, [.05 .85 .1 .1],…
‘String’, timestamp_str);
hold all;
x2 = [0, x1];
y2 = [0, y1];
z2 = [0, z1];
scatter3( x2, y2, z2);
F(j) = getframe(gcf);
frame = getframe(gcf);
writeVideo(writerObj, frame);
clf;
disp([num2str(j) ‘ / ‘ num2str(d_s(1))])
end
movie(F);
close(writerObj);
An image of the problem I’m having:
<<http://i.imgur.com/JS1wp26.png>> So I’m creating a movie model using data which describes a vector changing over time. I have the vector anchored at the origin and the head moves around according to the vector data. Because this is a bead-spring model, I want to graphically represent the beads by plotting circles at both ends of the vector. The problem I’m running into is that the bead that should be on the head of the vector is always offset by a certain amount. I can’t seem to figure out why it doesn’t have the same co-ords as the vector.
data = xlsread(‘C:UsersUserDocumentsMATLABData_Test.xlsx’,’Sheet1′);
t_s = data(:,1);
x_s = data(:,2);
y_s = data(:,3);
z_s = data(:,4);
d_s = size(t_s);
writerObj = VideoWriter(‘polymer.avi’);
open(writerObj);
for j = 1:d_s(1)
time = t_s(j);
x = x_s(j);
x1 = x*1000000;
y = y_s(j);
y1 = y*1000000;
z = z_s(j);
z1 = z*1000000;
h = quiver3(0, 0, 0, x1, y1, z1 );
set(h, ‘ShowArrowHead’, ‘off’);
axis([-5 15 -5 15 -5 15 3 5]);
title(‘it{Polymer Vibration}’,’FontSize’,16)
xlabel(‘x10^6′,’FontSize’,12);
ylabel(‘x10^6′,’FontSize’,12);
zlabel(‘x10^6′,’FontSize’,12);
timestamp_str = [‘t = ‘ num2str(time) ‘seconds’];
annotation(‘textbox’, [.05 .85 .1 .1],…
‘String’, timestamp_str);
hold all;
x2 = [0, x1];
y2 = [0, y1];
z2 = [0, z1];
scatter3( x2, y2, z2);
F(j) = getframe(gcf);
frame = getframe(gcf);
writeVideo(writerObj, frame);
clf;
disp([num2str(j) ‘ / ‘ num2str(d_s(1))])
end
movie(F);
close(writerObj);
An image of the problem I’m having:
<<http://i.imgur.com/JS1wp26.png>> plot quiver scatter MATLAB Answers — New Questions