Tag Archives: matlab
Is LEGO MINDSTORMS NXT supported in previous releases?
I would like to develop algorithms to run on LEGO MINDSTORMS NXT using Simulink and I would like to know if it is supported in previous releases.I would like to develop algorithms to run on LEGO MINDSTORMS NXT using Simulink and I would like to know if it is supported in previous releases. I would like to develop algorithms to run on LEGO MINDSTORMS NXT using Simulink and I would like to know if it is supported in previous releases. lego, mindstorms, nxt, simulink MATLAB Answers — New Questions
How do I change from 24 bit depth to 8 bit depth image?
I have image data for my input 256x256x3 uint8 and the bit depth is 24. My question is, how can I change from 24 bit depth image to 8 bit depth image without changing the colortype in ‘truecolor’? Here’s my ans value. And here’s my codes to read image and info image:-
>> I=imread(‘1234.png’);
>> imfinfo(‘1234.png’)I have image data for my input 256x256x3 uint8 and the bit depth is 24. My question is, how can I change from 24 bit depth image to 8 bit depth image without changing the colortype in ‘truecolor’? Here’s my ans value. And here’s my codes to read image and info image:-
>> I=imread(‘1234.png’);
>> imfinfo(‘1234.png’) I have image data for my input 256x256x3 uint8 and the bit depth is 24. My question is, how can I change from 24 bit depth image to 8 bit depth image without changing the colortype in ‘truecolor’? Here’s my ans value. And here’s my codes to read image and info image:-
>> I=imread(‘1234.png’);
>> imfinfo(‘1234.png’) bitdepth, image processing MATLAB Answers — New Questions
Why does my native library behave differently when wrapped using clibgen?
I have a native Windows library written in C++ and compiled with the MSVC compiler which contains one class (we’ll call it MyClass since I can’t provide the actual code for security reasons). MyClass has some std::vector<double> members that serve as input data to a MyClass member function (void myFun()–no input or output args) and also has some std::vector<double> members that serve as output parameters from that function.
I have also used clibgen to build a shared library so that MATLAB can use MyClass. However, I need to make sure that the outputs I get when both matlab and C++ call the function are EXACTLY the same, which I haven’t been able to achieve. To test equality between matlab and c++ I am doing the following:
Create a MyClass object in c++ (cppobj)
Populate the input parameters of cppobj
Run myFun() from cppobj
Write the input and output (all elements) of cppobj to binary files
Load the data of these binary files into two matlab objects, one with both inputs and outputs (matobj_cppout), and one with just inputs (matobj_matout)
Run myFun() on matobj_matout
Compare the output parameters of matobj_cppout and matobj_matout
I’ve calculated small differences in the output values even though they SHOULD be exactly the same, since the function is deterministic and the input parameters in matobj_cppout and matobj_matout are identical. This leads me to believe that MATLAB is doing some kind of conversion either when the binary files or read or when the values are stored to the native MyClass object using the "clib" functionality. I’ve verified that I’m using fp:precise both when building the native library and when running clibgen.
Any ideas of what could be causing these discrepancies?I have a native Windows library written in C++ and compiled with the MSVC compiler which contains one class (we’ll call it MyClass since I can’t provide the actual code for security reasons). MyClass has some std::vector<double> members that serve as input data to a MyClass member function (void myFun()–no input or output args) and also has some std::vector<double> members that serve as output parameters from that function.
I have also used clibgen to build a shared library so that MATLAB can use MyClass. However, I need to make sure that the outputs I get when both matlab and C++ call the function are EXACTLY the same, which I haven’t been able to achieve. To test equality between matlab and c++ I am doing the following:
Create a MyClass object in c++ (cppobj)
Populate the input parameters of cppobj
Run myFun() from cppobj
Write the input and output (all elements) of cppobj to binary files
Load the data of these binary files into two matlab objects, one with both inputs and outputs (matobj_cppout), and one with just inputs (matobj_matout)
Run myFun() on matobj_matout
Compare the output parameters of matobj_cppout and matobj_matout
I’ve calculated small differences in the output values even though they SHOULD be exactly the same, since the function is deterministic and the input parameters in matobj_cppout and matobj_matout are identical. This leads me to believe that MATLAB is doing some kind of conversion either when the binary files or read or when the values are stored to the native MyClass object using the "clib" functionality. I’ve verified that I’m using fp:precise both when building the native library and when running clibgen.
Any ideas of what could be causing these discrepancies? I have a native Windows library written in C++ and compiled with the MSVC compiler which contains one class (we’ll call it MyClass since I can’t provide the actual code for security reasons). MyClass has some std::vector<double> members that serve as input data to a MyClass member function (void myFun()–no input or output args) and also has some std::vector<double> members that serve as output parameters from that function.
I have also used clibgen to build a shared library so that MATLAB can use MyClass. However, I need to make sure that the outputs I get when both matlab and C++ call the function are EXACTLY the same, which I haven’t been able to achieve. To test equality between matlab and c++ I am doing the following:
Create a MyClass object in c++ (cppobj)
Populate the input parameters of cppobj
Run myFun() from cppobj
Write the input and output (all elements) of cppobj to binary files
Load the data of these binary files into two matlab objects, one with both inputs and outputs (matobj_cppout), and one with just inputs (matobj_matout)
Run myFun() on matobj_matout
Compare the output parameters of matobj_cppout and matobj_matout
I’ve calculated small differences in the output values even though they SHOULD be exactly the same, since the function is deterministic and the input parameters in matobj_cppout and matobj_matout are identical. This leads me to believe that MATLAB is doing some kind of conversion either when the binary files or read or when the values are stored to the native MyClass object using the "clib" functionality. I’ve verified that I’m using fp:precise both when building the native library and when running clibgen.
Any ideas of what could be causing these discrepancies? clibgen, native, c++ MATLAB Answers — New Questions
How compute connected node with each main node
I need to compute the totl number of green nodes and red nodes connected with each main node as shown in figure below
the code is in below
%Composing fixed nodes t
for h=1:1:num_fixed_nodes
S1(h).xd = position_region(i,1) + fixed_nodes{i, 1}(h,1);
S1(h).yd = position_region(i,2) + fixed_nodes{i, 1}(h,2);
S1(h).distance = sqrt((S1(h).xd-bs_x)^2 + (S1(h).yd-bs_y)^2 );
S1(h).G=0;
S1(h).id=h;
S1(h).type=’C’;
S1(h).temp = interp2(aa1,bb1,temp_values_1,S1(h).xd,S1(h).yd);
S1(h).E = Eo*rand(1,1);
Et=Et+S1(h).E;
S1(h).node_status = S1(h).temp<thresh_temp;
if(S1(h).node_status==1)
scatter(S1(h).xd,S1(h).yd, ‘filled’,’MarkerFaceColor’,’m’);
else
scatter(S1(h).xd,S1(h).yd, ‘filled’,’MarkerFaceColor’,’r’);
end
end
%Composing random nodes that will then communicate with fixed
%nodes
for h=num_fixed_nodes+1:1:num_nodes
%Generate random nodes within the region
S1(h).xd = position_region(i,1) + rand(1,1)*region_width;
S1(h).yd = position_region(i,2) + rand(1,1)*region_height;
S1(h).G=0;
S1(h).id=h;
S1(h).type=’N’;
S1(h).temp = interp2(aa1,bb1,temp_values_1,S1(h).xd,S1(h).yd);
S1(h).E=Eo*rand(1,1);
Et=Et+S1(h).E;
S1(h).node_status = S1(h).temp<thresh_temp;
if(S1(h).node_status==1)
scatter(S1(h).xd,S1(h).yd, ‘filled’,’MarkerFaceColor’,’g’);
else
scatter(S1(h).xd,S1(h).yd, ‘filled’,’MarkerFaceColor’,’r’);
endI need to compute the totl number of green nodes and red nodes connected with each main node as shown in figure below
the code is in below
%Composing fixed nodes t
for h=1:1:num_fixed_nodes
S1(h).xd = position_region(i,1) + fixed_nodes{i, 1}(h,1);
S1(h).yd = position_region(i,2) + fixed_nodes{i, 1}(h,2);
S1(h).distance = sqrt((S1(h).xd-bs_x)^2 + (S1(h).yd-bs_y)^2 );
S1(h).G=0;
S1(h).id=h;
S1(h).type=’C’;
S1(h).temp = interp2(aa1,bb1,temp_values_1,S1(h).xd,S1(h).yd);
S1(h).E = Eo*rand(1,1);
Et=Et+S1(h).E;
S1(h).node_status = S1(h).temp<thresh_temp;
if(S1(h).node_status==1)
scatter(S1(h).xd,S1(h).yd, ‘filled’,’MarkerFaceColor’,’m’);
else
scatter(S1(h).xd,S1(h).yd, ‘filled’,’MarkerFaceColor’,’r’);
end
end
%Composing random nodes that will then communicate with fixed
%nodes
for h=num_fixed_nodes+1:1:num_nodes
%Generate random nodes within the region
S1(h).xd = position_region(i,1) + rand(1,1)*region_width;
S1(h).yd = position_region(i,2) + rand(1,1)*region_height;
S1(h).G=0;
S1(h).id=h;
S1(h).type=’N’;
S1(h).temp = interp2(aa1,bb1,temp_values_1,S1(h).xd,S1(h).yd);
S1(h).E=Eo*rand(1,1);
Et=Et+S1(h).E;
S1(h).node_status = S1(h).temp<thresh_temp;
if(S1(h).node_status==1)
scatter(S1(h).xd,S1(h).yd, ‘filled’,’MarkerFaceColor’,’g’);
else
scatter(S1(h).xd,S1(h).yd, ‘filled’,’MarkerFaceColor’,’r’);
end I need to compute the totl number of green nodes and red nodes connected with each main node as shown in figure below
the code is in below
%Composing fixed nodes t
for h=1:1:num_fixed_nodes
S1(h).xd = position_region(i,1) + fixed_nodes{i, 1}(h,1);
S1(h).yd = position_region(i,2) + fixed_nodes{i, 1}(h,2);
S1(h).distance = sqrt((S1(h).xd-bs_x)^2 + (S1(h).yd-bs_y)^2 );
S1(h).G=0;
S1(h).id=h;
S1(h).type=’C’;
S1(h).temp = interp2(aa1,bb1,temp_values_1,S1(h).xd,S1(h).yd);
S1(h).E = Eo*rand(1,1);
Et=Et+S1(h).E;
S1(h).node_status = S1(h).temp<thresh_temp;
if(S1(h).node_status==1)
scatter(S1(h).xd,S1(h).yd, ‘filled’,’MarkerFaceColor’,’m’);
else
scatter(S1(h).xd,S1(h).yd, ‘filled’,’MarkerFaceColor’,’r’);
end
end
%Composing random nodes that will then communicate with fixed
%nodes
for h=num_fixed_nodes+1:1:num_nodes
%Generate random nodes within the region
S1(h).xd = position_region(i,1) + rand(1,1)*region_width;
S1(h).yd = position_region(i,2) + rand(1,1)*region_height;
S1(h).G=0;
S1(h).id=h;
S1(h).type=’N’;
S1(h).temp = interp2(aa1,bb1,temp_values_1,S1(h).xd,S1(h).yd);
S1(h).E=Eo*rand(1,1);
Et=Et+S1(h).E;
S1(h).node_status = S1(h).temp<thresh_temp;
if(S1(h).node_status==1)
scatter(S1(h).xd,S1(h).yd, ‘filled’,’MarkerFaceColor’,’g’);
else
scatter(S1(h).xd,S1(h).yd, ‘filled’,’MarkerFaceColor’,’r’);
end plotting, sum MATLAB Answers — New Questions
Could anyone tell me an accelerometer that will connect to matlab please?
Looking for accelerometers that I can buy online that will connect to matlabLooking for accelerometers that I can buy online that will connect to matlab Looking for accelerometers that I can buy online that will connect to matlab accelerometer, data acquisition, vibration MATLAB Answers — New Questions
How do I load pretrained LSTM models (in .mat format) into a MATLAB Function Block in Simulink?
I am trying to create a Simulink model for SoC and SoH prediction of a battery, in order to implement in Hardware-in-the-loop(HIL) using OP4512 simulator. Using Stateful predict block in MATLAB 2021a did not help as RT-LAB did not support the block during the real-time simulation. So, I have tried using a user defined function block for loading two LSTM models, which were trained using M code and has an RMSE of 0.2365%. I have used the following code for my function block:
function [soc,soh] = prediction(voltage, current, temperature, cycles)
persistent lstmNet lstmNet1;
if isempty(lstmNet)
lstmNet = coder.loadDeepLearningNetwork(‘net25_3layer.mat’);
end
if isempty(lstmNet1)
lstmNet1 = coder.loadDeepLearningNetwork(’12_5_23_SOH_optimised_3layer.mat’);
end
norm_voltage = (voltage-3.9102)/0.137;
norm_current = (current+0.8334)/2.4459;
norm_temperature = (temperature-24.5092)/0.3066;
norm_cycles = (cycles-174.9916)/114.5728;
X = [norm_voltage, norm_current, norm_temperature];
norm_soc = predict(lstmNet, X’);
soc = norm_soc*21.612+63.0467;
X1 = [norm_soc, norm_cycles];
norm_soh = predict(lstmNet1, X1′);
soh = norm_soh*33.6548+46.8586;
end
Also, I have set my simulation target language as C++.
When I run this model, I find that the output is in a different range (in case of SoC, 63% – 78%) than the output data in the dataset (In case of SoC, 28%-100%). This, I believe, is because the loadDeepLearningNetwork do not consider any recurrent computation in the network (correct me if I am wrong).
Is there any way I can load these two LSTM models into the function block such that I get the appropriate output?
Find the two .mat files (LSTM models) and the input variables in soc_sim_ws.mat file.I am trying to create a Simulink model for SoC and SoH prediction of a battery, in order to implement in Hardware-in-the-loop(HIL) using OP4512 simulator. Using Stateful predict block in MATLAB 2021a did not help as RT-LAB did not support the block during the real-time simulation. So, I have tried using a user defined function block for loading two LSTM models, which were trained using M code and has an RMSE of 0.2365%. I have used the following code for my function block:
function [soc,soh] = prediction(voltage, current, temperature, cycles)
persistent lstmNet lstmNet1;
if isempty(lstmNet)
lstmNet = coder.loadDeepLearningNetwork(‘net25_3layer.mat’);
end
if isempty(lstmNet1)
lstmNet1 = coder.loadDeepLearningNetwork(’12_5_23_SOH_optimised_3layer.mat’);
end
norm_voltage = (voltage-3.9102)/0.137;
norm_current = (current+0.8334)/2.4459;
norm_temperature = (temperature-24.5092)/0.3066;
norm_cycles = (cycles-174.9916)/114.5728;
X = [norm_voltage, norm_current, norm_temperature];
norm_soc = predict(lstmNet, X’);
soc = norm_soc*21.612+63.0467;
X1 = [norm_soc, norm_cycles];
norm_soh = predict(lstmNet1, X1′);
soh = norm_soh*33.6548+46.8586;
end
Also, I have set my simulation target language as C++.
When I run this model, I find that the output is in a different range (in case of SoC, 63% – 78%) than the output data in the dataset (In case of SoC, 28%-100%). This, I believe, is because the loadDeepLearningNetwork do not consider any recurrent computation in the network (correct me if I am wrong).
Is there any way I can load these two LSTM models into the function block such that I get the appropriate output?
Find the two .mat files (LSTM models) and the input variables in soc_sim_ws.mat file. I am trying to create a Simulink model for SoC and SoH prediction of a battery, in order to implement in Hardware-in-the-loop(HIL) using OP4512 simulator. Using Stateful predict block in MATLAB 2021a did not help as RT-LAB did not support the block during the real-time simulation. So, I have tried using a user defined function block for loading two LSTM models, which were trained using M code and has an RMSE of 0.2365%. I have used the following code for my function block:
function [soc,soh] = prediction(voltage, current, temperature, cycles)
persistent lstmNet lstmNet1;
if isempty(lstmNet)
lstmNet = coder.loadDeepLearningNetwork(‘net25_3layer.mat’);
end
if isempty(lstmNet1)
lstmNet1 = coder.loadDeepLearningNetwork(’12_5_23_SOH_optimised_3layer.mat’);
end
norm_voltage = (voltage-3.9102)/0.137;
norm_current = (current+0.8334)/2.4459;
norm_temperature = (temperature-24.5092)/0.3066;
norm_cycles = (cycles-174.9916)/114.5728;
X = [norm_voltage, norm_current, norm_temperature];
norm_soc = predict(lstmNet, X’);
soc = norm_soc*21.612+63.0467;
X1 = [norm_soc, norm_cycles];
norm_soh = predict(lstmNet1, X1′);
soh = norm_soh*33.6548+46.8586;
end
Also, I have set my simulation target language as C++.
When I run this model, I find that the output is in a different range (in case of SoC, 63% – 78%) than the output data in the dataset (In case of SoC, 28%-100%). This, I believe, is because the loadDeepLearningNetwork do not consider any recurrent computation in the network (correct me if I am wrong).
Is there any way I can load these two LSTM models into the function block such that I get the appropriate output?
Find the two .mat files (LSTM models) and the input variables in soc_sim_ws.mat file. simulink, lstm, function block MATLAB Answers — New Questions
how do i put MATLAB complex array to python?
I want to python code in MATLAB.(use pyrunfile)
I can’t put complex array into python.
I’m testing very simple code.
python core:(file :Test.py):
print(indat)
MATLAB(inline input):
adat=xxx
pyrunfile("./Test.py",indat=adat)
I got results under below.
Case A: input adat=1+0.1i (MATALB inline)
output (1+0.1j)
Case A is OK
Case B: input adat=[1,2,3]
output array(‘d’, [1.0, 2.0, 3.0])
Case B is OK
Case C:input adat=[1+0.1i,2+0.2i,3+0.3i]
Output <memory at 0x000002562F9E9560>
Why?
what should i do put complex array into python?I want to python code in MATLAB.(use pyrunfile)
I can’t put complex array into python.
I’m testing very simple code.
python core:(file :Test.py):
print(indat)
MATLAB(inline input):
adat=xxx
pyrunfile("./Test.py",indat=adat)
I got results under below.
Case A: input adat=1+0.1i (MATALB inline)
output (1+0.1j)
Case A is OK
Case B: input adat=[1,2,3]
output array(‘d’, [1.0, 2.0, 3.0])
Case B is OK
Case C:input adat=[1+0.1i,2+0.2i,3+0.3i]
Output <memory at 0x000002562F9E9560>
Why?
what should i do put complex array into python? I want to python code in MATLAB.(use pyrunfile)
I can’t put complex array into python.
I’m testing very simple code.
python core:(file :Test.py):
print(indat)
MATLAB(inline input):
adat=xxx
pyrunfile("./Test.py",indat=adat)
I got results under below.
Case A: input adat=1+0.1i (MATALB inline)
output (1+0.1j)
Case A is OK
Case B: input adat=[1,2,3]
output array(‘d’, [1.0, 2.0, 3.0])
Case B is OK
Case C:input adat=[1+0.1i,2+0.2i,3+0.3i]
Output <memory at 0x000002562F9E9560>
Why?
what should i do put complex array into python? complex array, python MATLAB Answers — New Questions
How can I keep a function operating while the screen is locked?
using MATLAB 2014A on macOS 10.11.6, I am running a function from the command line, and when I lock the screen the function suspends activity until I unlock it again.using MATLAB 2014A on macOS 10.11.6, I am running a function from the command line, and when I lock the screen the function suspends activity until I unlock it again. using MATLAB 2014A on macOS 10.11.6, I am running a function from the command line, and when I lock the screen the function suspends activity until I unlock it again. suspended job MATLAB Answers — New Questions
genetic algorithm with integer constraint returns non-integer solution
I was solving the Four Peaks Problem[1] using ga function in MATLAB.
This problem has an integer constraint and the solution is expected to be in integers, but MATLAB’s ga function returns non-integer solution, although they are almost integers.
Following is the code. I expect to see
oz = [21.0000 79.0000], and fval = -179.0000
but I see
oz = [21.0000 79.0010], and fval = -179.0010
Well, they are, like I said, almost integers, so I surely can interpret them, but I was just curious. Is this expected output? Or is the function missing something during the postprocessing?
%% Setup
close
clear
clc
% for reproducibility
rng(1,’twister’)
% length of the bit string
N = 100;
% threshold
T = 20;
% Pass in fixed parameters to objfun.
objfun = @(oz) -four_peaks(oz,T,N);
% constraints
INTCON = [1, 1]; % integer constraints: Both o and z must be integers.
lb = [0, 0]; % Both o and z cannot be negative.
ub = [N,N]; % Both o and z cannot be greater than the length of the bit string.
A = [1,1]; b = N; % inequality constraint: o+z < length of the bit string.
%% Solve
% Solve
[oz,fval,exitflag,output,population,scores] = ga(objfun,2,A,b,[],[],lb,ub,[],INTCON);
%% Report
disp(oz)
disp(-fval)
%% Object Function
function y = four_peaks(x, T, N)
if x(1) > T && x(2) > T
y = max(x) + N;
else
y = max(x);
end
endI was solving the Four Peaks Problem[1] using ga function in MATLAB.
This problem has an integer constraint and the solution is expected to be in integers, but MATLAB’s ga function returns non-integer solution, although they are almost integers.
Following is the code. I expect to see
oz = [21.0000 79.0000], and fval = -179.0000
but I see
oz = [21.0000 79.0010], and fval = -179.0010
Well, they are, like I said, almost integers, so I surely can interpret them, but I was just curious. Is this expected output? Or is the function missing something during the postprocessing?
%% Setup
close
clear
clc
% for reproducibility
rng(1,’twister’)
% length of the bit string
N = 100;
% threshold
T = 20;
% Pass in fixed parameters to objfun.
objfun = @(oz) -four_peaks(oz,T,N);
% constraints
INTCON = [1, 1]; % integer constraints: Both o and z must be integers.
lb = [0, 0]; % Both o and z cannot be negative.
ub = [N,N]; % Both o and z cannot be greater than the length of the bit string.
A = [1,1]; b = N; % inequality constraint: o+z < length of the bit string.
%% Solve
% Solve
[oz,fval,exitflag,output,population,scores] = ga(objfun,2,A,b,[],[],lb,ub,[],INTCON);
%% Report
disp(oz)
disp(-fval)
%% Object Function
function y = four_peaks(x, T, N)
if x(1) > T && x(2) > T
y = max(x) + N;
else
y = max(x);
end
end I was solving the Four Peaks Problem[1] using ga function in MATLAB.
This problem has an integer constraint and the solution is expected to be in integers, but MATLAB’s ga function returns non-integer solution, although they are almost integers.
Following is the code. I expect to see
oz = [21.0000 79.0000], and fval = -179.0000
but I see
oz = [21.0000 79.0010], and fval = -179.0010
Well, they are, like I said, almost integers, so I surely can interpret them, but I was just curious. Is this expected output? Or is the function missing something during the postprocessing?
%% Setup
close
clear
clc
% for reproducibility
rng(1,’twister’)
% length of the bit string
N = 100;
% threshold
T = 20;
% Pass in fixed parameters to objfun.
objfun = @(oz) -four_peaks(oz,T,N);
% constraints
INTCON = [1, 1]; % integer constraints: Both o and z must be integers.
lb = [0, 0]; % Both o and z cannot be negative.
ub = [N,N]; % Both o and z cannot be greater than the length of the bit string.
A = [1,1]; b = N; % inequality constraint: o+z < length of the bit string.
%% Solve
% Solve
[oz,fval,exitflag,output,population,scores] = ga(objfun,2,A,b,[],[],lb,ub,[],INTCON);
%% Report
disp(oz)
disp(-fval)
%% Object Function
function y = four_peaks(x, T, N)
if x(1) > T && x(2) > T
y = max(x) + N;
else
y = max(x);
end
end genetic algorithm, four peaks problem MATLAB Answers — New Questions
出现需要使用’Level-2 MATLAB S-Function’的错误
S函数程序为
function calculate_gain_sfunc(block)
setup(block);
end
function setup(block)
% Register the number of ports
block.NumInputPorts = 3; % Q1, Q2, and F2(t)
block.NumOutputPorts = 2; % y1 and y2
% Set up the input and output ports
block.SetPreCompInpPortInfoToDynamic;
block.SetPreCompOutPortInfoToDynamic;
block.InputPort(1).Dimensions = 1; % Q1
block.InputPort(2).Dimensions = 1; % Q2
block.InputPort(3).Dimensions = 1; % F2
block.OutputPort(1).Dimensions = 1; % y1
block.OutputPort(2).Dimensions = 1; % y2
% Register the parameters
block.NumDialogPrms = 9; % J1, L1, R1, AE, F1, J2, L2, R2
% Set the sample time
block.SampleTimes = [0 0];
% Specify the block simStateCompliance
block.SimStateCompliance = ‘DefaultSimState’;
% Register the methods
block.RegBlockMethod(‘Outputs’, @Output); % Register the output method
end
function Output(block)
% Get the inputs
Q1 = block.InputPort(1).Data;
Q2 = block.InputPort(2).Data;
F2 = block.InputPort(3).Data;
% Get the parameters
J1 = block.DialogPrm(1).Data;
L1 = block.DialogPrm(2).Data;
R1 = block.DialogPrm(3).Data;
AE = block.DialogPrm(4).Data;
F1 = block.DialogPrm(5).Data;
J2 = block.DialogPrm(6).Data;
L2 = block.DialogPrm(7).Data;
R2 = block.DialogPrm(8).Data;
% Compute the gains
gain1 = J1 * L1 / (R1 * (AE – F1));
gain2 = J2 * L2 / (R2 * (F2 – AE));
% Compute the outputs
y1 = gain1 * Q1;
y2 = gain2 * Q2;
% Set the outputs
block.OutputPort(1).Data = y1;
block.OutputPort(2).Data = y2;
end
模型如上图所示
simulink运行结果为:
The specified MATLAB File ‘calculate_gain_sfunc’ in ‘sys/S-Function1’ is not a valid Level 1 S-Function. The number of input and/or output arguments is not valid. A likely cause for this error is that the name of a level-2 MATLAB S-function has been specified in this block (which supports only level-1 MATLAB S-functions). Use the ‘Level-2 MATLAB S-Function’ block from the Simulink libraryS函数程序为
function calculate_gain_sfunc(block)
setup(block);
end
function setup(block)
% Register the number of ports
block.NumInputPorts = 3; % Q1, Q2, and F2(t)
block.NumOutputPorts = 2; % y1 and y2
% Set up the input and output ports
block.SetPreCompInpPortInfoToDynamic;
block.SetPreCompOutPortInfoToDynamic;
block.InputPort(1).Dimensions = 1; % Q1
block.InputPort(2).Dimensions = 1; % Q2
block.InputPort(3).Dimensions = 1; % F2
block.OutputPort(1).Dimensions = 1; % y1
block.OutputPort(2).Dimensions = 1; % y2
% Register the parameters
block.NumDialogPrms = 9; % J1, L1, R1, AE, F1, J2, L2, R2
% Set the sample time
block.SampleTimes = [0 0];
% Specify the block simStateCompliance
block.SimStateCompliance = ‘DefaultSimState’;
% Register the methods
block.RegBlockMethod(‘Outputs’, @Output); % Register the output method
end
function Output(block)
% Get the inputs
Q1 = block.InputPort(1).Data;
Q2 = block.InputPort(2).Data;
F2 = block.InputPort(3).Data;
% Get the parameters
J1 = block.DialogPrm(1).Data;
L1 = block.DialogPrm(2).Data;
R1 = block.DialogPrm(3).Data;
AE = block.DialogPrm(4).Data;
F1 = block.DialogPrm(5).Data;
J2 = block.DialogPrm(6).Data;
L2 = block.DialogPrm(7).Data;
R2 = block.DialogPrm(8).Data;
% Compute the gains
gain1 = J1 * L1 / (R1 * (AE – F1));
gain2 = J2 * L2 / (R2 * (F2 – AE));
% Compute the outputs
y1 = gain1 * Q1;
y2 = gain2 * Q2;
% Set the outputs
block.OutputPort(1).Data = y1;
block.OutputPort(2).Data = y2;
end
模型如上图所示
simulink运行结果为:
The specified MATLAB File ‘calculate_gain_sfunc’ in ‘sys/S-Function1’ is not a valid Level 1 S-Function. The number of input and/or output arguments is not valid. A likely cause for this error is that the name of a level-2 MATLAB S-function has been specified in this block (which supports only level-1 MATLAB S-functions). Use the ‘Level-2 MATLAB S-Function’ block from the Simulink library S函数程序为
function calculate_gain_sfunc(block)
setup(block);
end
function setup(block)
% Register the number of ports
block.NumInputPorts = 3; % Q1, Q2, and F2(t)
block.NumOutputPorts = 2; % y1 and y2
% Set up the input and output ports
block.SetPreCompInpPortInfoToDynamic;
block.SetPreCompOutPortInfoToDynamic;
block.InputPort(1).Dimensions = 1; % Q1
block.InputPort(2).Dimensions = 1; % Q2
block.InputPort(3).Dimensions = 1; % F2
block.OutputPort(1).Dimensions = 1; % y1
block.OutputPort(2).Dimensions = 1; % y2
% Register the parameters
block.NumDialogPrms = 9; % J1, L1, R1, AE, F1, J2, L2, R2
% Set the sample time
block.SampleTimes = [0 0];
% Specify the block simStateCompliance
block.SimStateCompliance = ‘DefaultSimState’;
% Register the methods
block.RegBlockMethod(‘Outputs’, @Output); % Register the output method
end
function Output(block)
% Get the inputs
Q1 = block.InputPort(1).Data;
Q2 = block.InputPort(2).Data;
F2 = block.InputPort(3).Data;
% Get the parameters
J1 = block.DialogPrm(1).Data;
L1 = block.DialogPrm(2).Data;
R1 = block.DialogPrm(3).Data;
AE = block.DialogPrm(4).Data;
F1 = block.DialogPrm(5).Data;
J2 = block.DialogPrm(6).Data;
L2 = block.DialogPrm(7).Data;
R2 = block.DialogPrm(8).Data;
% Compute the gains
gain1 = J1 * L1 / (R1 * (AE – F1));
gain2 = J2 * L2 / (R2 * (F2 – AE));
% Compute the outputs
y1 = gain1 * Q1;
y2 = gain2 * Q2;
% Set the outputs
block.OutputPort(1).Data = y1;
block.OutputPort(2).Data = y2;
end
模型如上图所示
simulink运行结果为:
The specified MATLAB File ‘calculate_gain_sfunc’ in ‘sys/S-Function1’ is not a valid Level 1 S-Function. The number of input and/or output arguments is not valid. A likely cause for this error is that the name of a level-2 MATLAB S-function has been specified in this block (which supports only level-1 MATLAB S-functions). Use the ‘Level-2 MATLAB S-Function’ block from the Simulink library 2018b MATLAB Answers — New Questions
how to combined monthly data in sequence?
hello all,
I have a time series data for 10 year (lat X lon X 120). For taking monthly mean of every jan, feb…. dec, I have separated jan to dec data
jan = data(:,:,[1:12:10]);
feb = data(:,:,[2:12:10]);
mar = data(:,:,[3:12:10]);
aprl = data(:,:,[4:12:10]);………..
Then I have taken mean,
jan_mean = mean(jan(:,:,1:10),3); feb_mean = mean(feb(:,:,1:10),3); ……………………………………………….dec_mean = mean(dec(:,:,1:10),3);
For calculation of anomaly, Anom_jan = jan – jan_mean, Anom_feb = feb – feb_mean………………….
Now, I want to combined all these Anom timeseries in seuence (lat X lon X 120).
how to merge theses timeseries in sequece of jan to dec of ever year?hello all,
I have a time series data for 10 year (lat X lon X 120). For taking monthly mean of every jan, feb…. dec, I have separated jan to dec data
jan = data(:,:,[1:12:10]);
feb = data(:,:,[2:12:10]);
mar = data(:,:,[3:12:10]);
aprl = data(:,:,[4:12:10]);………..
Then I have taken mean,
jan_mean = mean(jan(:,:,1:10),3); feb_mean = mean(feb(:,:,1:10),3); ……………………………………………….dec_mean = mean(dec(:,:,1:10),3);
For calculation of anomaly, Anom_jan = jan – jan_mean, Anom_feb = feb – feb_mean………………….
Now, I want to combined all these Anom timeseries in seuence (lat X lon X 120).
how to merge theses timeseries in sequece of jan to dec of ever year? hello all,
I have a time series data for 10 year (lat X lon X 120). For taking monthly mean of every jan, feb…. dec, I have separated jan to dec data
jan = data(:,:,[1:12:10]);
feb = data(:,:,[2:12:10]);
mar = data(:,:,[3:12:10]);
aprl = data(:,:,[4:12:10]);………..
Then I have taken mean,
jan_mean = mean(jan(:,:,1:10),3); feb_mean = mean(feb(:,:,1:10),3); ……………………………………………….dec_mean = mean(dec(:,:,1:10),3);
For calculation of anomaly, Anom_jan = jan – jan_mean, Anom_feb = feb – feb_mean………………….
Now, I want to combined all these Anom timeseries in seuence (lat X lon X 120).
how to merge theses timeseries in sequece of jan to dec of ever year? time series, matrix, vector MATLAB Answers — New Questions
How to take 1 out of every 10 values from a vector?
Hello, I have problems with a vector that I am working with, it has more than 10,000 elements, but I just need to know the trend of these, so I would like to take 1 out of every 10 values to graph it, could you suggest a way to obtain it please?Hello, I have problems with a vector that I am working with, it has more than 10,000 elements, but I just need to know the trend of these, so I would like to take 1 out of every 10 values to graph it, could you suggest a way to obtain it please? Hello, I have problems with a vector that I am working with, it has more than 10,000 elements, but I just need to know the trend of these, so I would like to take 1 out of every 10 values to graph it, could you suggest a way to obtain it please? vector MATLAB Answers — New Questions
Use symbolic dimensions in Simulink model for code generation
I’m trying to create a MACRO to be used as dimension in the simulink model. The definition is as follows:
IDXLIM = Simulink.Parameter;
IDXLIM.Value = uint8(100.0);
IDXLIM.CoderInfo.StorageClass = ‘Custom’;
IDXLIM.CoderInfo.CustomStorageClass = ‘Define’;
IDXLIM.Description = ‘Macro to loop for Input vector Iteraton limit’;
IDXLIM.DataType = ‘uint8’;
IDXLIM.Min = [];
IDXLIM.Max = [];
IDXLIM.Unit = ‘Unitless’;
The following MACRO is used in the model and AllowSymbolicDimensions is enabled and as per the documentation, the code genration should be possible, but I see the following error:
Unsupported custom storage class ‘Default’ for symbolic dimension IDXLIM. Specify one of the following custom storage classes:
– Define or ImportedDefine with header file specified
– CompilerFlag
– SystemConstant (AUTOSAR.Parameter)
– User-defined custom storage class that defines data as a macro in a specified header file
To disable symbolic dimension propagation, search for ‘Allow symbolic dimension specification’ in the Configuration Parameters dialog box and clear the checkbox.
How to resolve this issue?I’m trying to create a MACRO to be used as dimension in the simulink model. The definition is as follows:
IDXLIM = Simulink.Parameter;
IDXLIM.Value = uint8(100.0);
IDXLIM.CoderInfo.StorageClass = ‘Custom’;
IDXLIM.CoderInfo.CustomStorageClass = ‘Define’;
IDXLIM.Description = ‘Macro to loop for Input vector Iteraton limit’;
IDXLIM.DataType = ‘uint8’;
IDXLIM.Min = [];
IDXLIM.Max = [];
IDXLIM.Unit = ‘Unitless’;
The following MACRO is used in the model and AllowSymbolicDimensions is enabled and as per the documentation, the code genration should be possible, but I see the following error:
Unsupported custom storage class ‘Default’ for symbolic dimension IDXLIM. Specify one of the following custom storage classes:
– Define or ImportedDefine with header file specified
– CompilerFlag
– SystemConstant (AUTOSAR.Parameter)
– User-defined custom storage class that defines data as a macro in a specified header file
To disable symbolic dimension propagation, search for ‘Allow symbolic dimension specification’ in the Configuration Parameters dialog box and clear the checkbox.
How to resolve this issue? I’m trying to create a MACRO to be used as dimension in the simulink model. The definition is as follows:
IDXLIM = Simulink.Parameter;
IDXLIM.Value = uint8(100.0);
IDXLIM.CoderInfo.StorageClass = ‘Custom’;
IDXLIM.CoderInfo.CustomStorageClass = ‘Define’;
IDXLIM.Description = ‘Macro to loop for Input vector Iteraton limit’;
IDXLIM.DataType = ‘uint8’;
IDXLIM.Min = [];
IDXLIM.Max = [];
IDXLIM.Unit = ‘Unitless’;
The following MACRO is used in the model and AllowSymbolicDimensions is enabled and as per the documentation, the code genration should be possible, but I see the following error:
Unsupported custom storage class ‘Default’ for symbolic dimension IDXLIM. Specify one of the following custom storage classes:
– Define or ImportedDefine with header file specified
– CompilerFlag
– SystemConstant (AUTOSAR.Parameter)
– User-defined custom storage class that defines data as a macro in a specified header file
To disable symbolic dimension propagation, search for ‘Allow symbolic dimension specification’ in the Configuration Parameters dialog box and clear the checkbox.
How to resolve this issue? embedded coder, storage classes MATLAB Answers — New Questions
Convert bitdepth of png image
How to convert the image with the following information: ColorType: truecolor Format: png bitDepth: 24
to a png grayscale image with bitdepth=8 in matlab ?How to convert the image with the following information: ColorType: truecolor Format: png bitDepth: 24
to a png grayscale image with bitdepth=8 in matlab ? How to convert the image with the following information: ColorType: truecolor Format: png bitDepth: 24
to a png grayscale image with bitdepth=8 in matlab ? png, bitdepth, grayscale MATLAB Answers — New Questions
can I disable entire sections of code temporarily
Can I disable entire sections of code temporarily?
I have a large code that contains different scenarios. I’m working on one scenario and I’d like to disable the other sections, just while I’m working on that bit so that I can run the code quickly without having to wait for it to do all the other stuff too.Can I disable entire sections of code temporarily?
I have a large code that contains different scenarios. I’m working on one scenario and I’d like to disable the other sections, just while I’m working on that bit so that I can run the code quickly without having to wait for it to do all the other stuff too. Can I disable entire sections of code temporarily?
I have a large code that contains different scenarios. I’m working on one scenario and I’d like to disable the other sections, just while I’m working on that bit so that I can run the code quickly without having to wait for it to do all the other stuff too. if MATLAB Answers — New Questions
I want to know the properties of ray instead of each path in Matlab ray-tracer for RF propagation
Hi, I am trying to buid an AI model pridict the the properties of an RF ray after an interaction with an object and want to create the data set using matlab. I came accross a tutorial that shows how to get different properties of a path (I think) but is there a way to get the information of each ray. for example when it hit an obsticle/material these were the properties and when it bounced off these were the properties.
thanks in advanceHi, I am trying to buid an AI model pridict the the properties of an RF ray after an interaction with an object and want to create the data set using matlab. I came accross a tutorial that shows how to get different properties of a path (I think) but is there a way to get the information of each ray. for example when it hit an obsticle/material these were the properties and when it bounced off these were the properties.
thanks in advance Hi, I am trying to buid an AI model pridict the the properties of an RF ray after an interaction with an object and want to create the data set using matlab. I came accross a tutorial that shows how to get different properties of a path (I think) but is there a way to get the information of each ray. for example when it hit an obsticle/material these were the properties and when it bounced off these were the properties.
thanks in advance rayt racing, radio propogation MATLAB Answers — New Questions
How to modify the static Java path
The instructions here describe how to add JAR files to the bottom of the static Java path. Dynamic entries also are used last. This means we cannot replace any of the JAR files that come with MATLAB.
I have an Apple Silicon machine, MATLAB R2023b, and Amazon Coretto JVM installed according to the MATLAB installation instructions.
This version of MATLAB comes with a jna.jar in $MATLABROOT/java/jarext/svnkit/jna.jar that doesn’t work in Apple Silicon (it has a shared object built in that works on i386, x86_64 and ppc7400 (which makes me think this is a really old version!).
I’ve downloaded a newer version of this JAR, but I cannot get MATLAB to use the newer version. Is my only hope to overwrite the file that comes with MATLAB?The instructions here describe how to add JAR files to the bottom of the static Java path. Dynamic entries also are used last. This means we cannot replace any of the JAR files that come with MATLAB.
I have an Apple Silicon machine, MATLAB R2023b, and Amazon Coretto JVM installed according to the MATLAB installation instructions.
This version of MATLAB comes with a jna.jar in $MATLABROOT/java/jarext/svnkit/jna.jar that doesn’t work in Apple Silicon (it has a shared object built in that works on i386, x86_64 and ppc7400 (which makes me think this is a really old version!).
I’ve downloaded a newer version of this JAR, but I cannot get MATLAB to use the newer version. Is my only hope to overwrite the file that comes with MATLAB? The instructions here describe how to add JAR files to the bottom of the static Java path. Dynamic entries also are used last. This means we cannot replace any of the JAR files that come with MATLAB.
I have an Apple Silicon machine, MATLAB R2023b, and Amazon Coretto JVM installed according to the MATLAB installation instructions.
This version of MATLAB comes with a jna.jar in $MATLABROOT/java/jarext/svnkit/jna.jar that doesn’t work in Apple Silicon (it has a shared object built in that works on i386, x86_64 and ppc7400 (which makes me think this is a really old version!).
I’ve downloaded a newer version of this JAR, but I cannot get MATLAB to use the newer version. Is my only hope to overwrite the file that comes with MATLAB? java, javaclasspath, jar MATLAB Answers — New Questions
Global struct or separate globals for callback optimization?
If I needed a collection globals to store actively updated information, would it be better (run faster, run more efficiently, have less possibilities for bugs) to have a global struct in place of multiple globals? The various callbacks that update the information don’t use every single global, so a struct would bring along extra information in many of the places it is needed.
The motivation for this question is the UI I have designed, as globals are the only way that I currently understand how to enable interrupting callbacks to change the value of a variable that must be recognized by the interrupted callback. There is likely a better way to do this that doesn’t use globals, but my browsing didn’t reveal anything simple enough for my skill level and deadline. (please link alternatives to globals)!
Example:
%lines stores line graphics objects with 2 axes of 3-dimensional data
%each row in this array is an increment of the 3rd dimension
global lines; %is global for interrupting property changes of lines
lines = gobjects(80,4); %80 lines for each of 4 data sets
%Whether or not a playback iterating through each row of lines stops itself
global pauseState;
pauseState = true;
Where they would be replaced by the struct
global s;
s = struct(‘paused’,true,’lines’,gobjects(80,4))
Used by the callback functions
function pause()
global pauseState; %Here only one global is used, struct would be wasteful?
pauseState = true;
end
%While play() is running, pause() is called, interrupting and breaking the loop
function play()
global pauseState; %Here both globals are used, struct would be more compact
%global delay; %Another possible global
global lines;
%global lines2;
pauseState = false;
for i=1:1:height(lines)
if pauseState == true
break;
end
%do stuff
%[lines(i,:).Visibility] = deal(‘on’); %or something
%drawnow;
%pause(delay); %Dictate pacing of play loop
end
end
For the sake of simplicity, the operative code within play() is omitted since there would need to be more than placeholder graphics objects.
This example is not too far off from what a portion of my UI actually does, so these are some of the circumstances in which the struct substitution would be employed. I’m not sure of other cases.
The globals used here are of drastically different sizes, which I mention since the answer to this question may depend greatly on the size of the globals that would be replaced by the struct. Not all of the globals I am using are so polarized in size, like how "delay" and "pauseState" are a double and a logical value (both small).
Thank you!
Notes: I do not have any run errors or warnings, and I have not run into any issues with using multiple globals. I also use the clear; command at the top of my file which may be why I haven’t run into any issues with globals. The two callback functions here are used with uibutton objects.If I needed a collection globals to store actively updated information, would it be better (run faster, run more efficiently, have less possibilities for bugs) to have a global struct in place of multiple globals? The various callbacks that update the information don’t use every single global, so a struct would bring along extra information in many of the places it is needed.
The motivation for this question is the UI I have designed, as globals are the only way that I currently understand how to enable interrupting callbacks to change the value of a variable that must be recognized by the interrupted callback. There is likely a better way to do this that doesn’t use globals, but my browsing didn’t reveal anything simple enough for my skill level and deadline. (please link alternatives to globals)!
Example:
%lines stores line graphics objects with 2 axes of 3-dimensional data
%each row in this array is an increment of the 3rd dimension
global lines; %is global for interrupting property changes of lines
lines = gobjects(80,4); %80 lines for each of 4 data sets
%Whether or not a playback iterating through each row of lines stops itself
global pauseState;
pauseState = true;
Where they would be replaced by the struct
global s;
s = struct(‘paused’,true,’lines’,gobjects(80,4))
Used by the callback functions
function pause()
global pauseState; %Here only one global is used, struct would be wasteful?
pauseState = true;
end
%While play() is running, pause() is called, interrupting and breaking the loop
function play()
global pauseState; %Here both globals are used, struct would be more compact
%global delay; %Another possible global
global lines;
%global lines2;
pauseState = false;
for i=1:1:height(lines)
if pauseState == true
break;
end
%do stuff
%[lines(i,:).Visibility] = deal(‘on’); %or something
%drawnow;
%pause(delay); %Dictate pacing of play loop
end
end
For the sake of simplicity, the operative code within play() is omitted since there would need to be more than placeholder graphics objects.
This example is not too far off from what a portion of my UI actually does, so these are some of the circumstances in which the struct substitution would be employed. I’m not sure of other cases.
The globals used here are of drastically different sizes, which I mention since the answer to this question may depend greatly on the size of the globals that would be replaced by the struct. Not all of the globals I am using are so polarized in size, like how "delay" and "pauseState" are a double and a logical value (both small).
Thank you!
Notes: I do not have any run errors or warnings, and I have not run into any issues with using multiple globals. I also use the clear; command at the top of my file which may be why I haven’t run into any issues with globals. The two callback functions here are used with uibutton objects. If I needed a collection globals to store actively updated information, would it be better (run faster, run more efficiently, have less possibilities for bugs) to have a global struct in place of multiple globals? The various callbacks that update the information don’t use every single global, so a struct would bring along extra information in many of the places it is needed.
The motivation for this question is the UI I have designed, as globals are the only way that I currently understand how to enable interrupting callbacks to change the value of a variable that must be recognized by the interrupted callback. There is likely a better way to do this that doesn’t use globals, but my browsing didn’t reveal anything simple enough for my skill level and deadline. (please link alternatives to globals)!
Example:
%lines stores line graphics objects with 2 axes of 3-dimensional data
%each row in this array is an increment of the 3rd dimension
global lines; %is global for interrupting property changes of lines
lines = gobjects(80,4); %80 lines for each of 4 data sets
%Whether or not a playback iterating through each row of lines stops itself
global pauseState;
pauseState = true;
Where they would be replaced by the struct
global s;
s = struct(‘paused’,true,’lines’,gobjects(80,4))
Used by the callback functions
function pause()
global pauseState; %Here only one global is used, struct would be wasteful?
pauseState = true;
end
%While play() is running, pause() is called, interrupting and breaking the loop
function play()
global pauseState; %Here both globals are used, struct would be more compact
%global delay; %Another possible global
global lines;
%global lines2;
pauseState = false;
for i=1:1:height(lines)
if pauseState == true
break;
end
%do stuff
%[lines(i,:).Visibility] = deal(‘on’); %or something
%drawnow;
%pause(delay); %Dictate pacing of play loop
end
end
For the sake of simplicity, the operative code within play() is omitted since there would need to be more than placeholder graphics objects.
This example is not too far off from what a portion of my UI actually does, so these are some of the circumstances in which the struct substitution would be employed. I’m not sure of other cases.
The globals used here are of drastically different sizes, which I mention since the answer to this question may depend greatly on the size of the globals that would be replaced by the struct. Not all of the globals I am using are so polarized in size, like how "delay" and "pauseState" are a double and a logical value (both small).
Thank you!
Notes: I do not have any run errors or warnings, and I have not run into any issues with using multiple globals. I also use the clear; command at the top of my file which may be why I haven’t run into any issues with globals. The two callback functions here are used with uibutton objects. globals, callback, gui, struct, interruption MATLAB Answers — New Questions
How do I get a colormap for my image?
When I import my image using the imread function, I get a map with only zeros (map = []). I want the RGB components of the image, but cannot get them since this requires the picture’s colormap (which is empty). This is the code I’m using:
filename = uigetfile(‘*.*’);
[X, map] = imread(filename);
info = imfinfo(filename)
width = getfield(imfinfo(filename),’Width’)
height = getfield(imfinfo(filename),’Height’)
figure(‘Name’,’Display imported image’,’NumberTitle’,’off’);
image(X);
rgb = ind2rgb(X,map);
The info of the image is:
info =
Filename: ’11-11-11 (30).JPG’
FileModDate: ’11-Nov-2011 21:07:46′
FileSize: 4549123
Format: ‘jpg’
FormatVersion: ”
Width: 4320
Height: 2432
BitDepth: 24
ColorType: ‘truecolor’
FormatSignature: ”
NumberOfSamples: 3
CodingMethod: ‘Huffman’
CodingProcess: ‘Sequential’
Comment: {}
ImageDescription: ‘ ‘
Make: ‘SONY ‘
Model: ‘DSC-W350 ‘
Orientation: 1
XResolution: 72
YResolution: 72
ResolutionUnit: ‘Inch’
DateTime: ‘2011:11:11 21:07:46 ‘
YCbCrPositioning: ‘Co-sited’
DigitalCamera: [1×1 struct]
UnknownTags: [1×1 struct]
ExifThumbnail: [1×1 struct]
And then I get this error message:
??? Index exceeds matrix dimensions.
Error in ==> ind2rgb at 27
r = zeros(size(a)); r(:) = cm(a,1);
Error in ==> DSP_LCK at 24
rgb = ind2rgb(X,map);
Some advice please?When I import my image using the imread function, I get a map with only zeros (map = []). I want the RGB components of the image, but cannot get them since this requires the picture’s colormap (which is empty). This is the code I’m using:
filename = uigetfile(‘*.*’);
[X, map] = imread(filename);
info = imfinfo(filename)
width = getfield(imfinfo(filename),’Width’)
height = getfield(imfinfo(filename),’Height’)
figure(‘Name’,’Display imported image’,’NumberTitle’,’off’);
image(X);
rgb = ind2rgb(X,map);
The info of the image is:
info =
Filename: ’11-11-11 (30).JPG’
FileModDate: ’11-Nov-2011 21:07:46′
FileSize: 4549123
Format: ‘jpg’
FormatVersion: ”
Width: 4320
Height: 2432
BitDepth: 24
ColorType: ‘truecolor’
FormatSignature: ”
NumberOfSamples: 3
CodingMethod: ‘Huffman’
CodingProcess: ‘Sequential’
Comment: {}
ImageDescription: ‘ ‘
Make: ‘SONY ‘
Model: ‘DSC-W350 ‘
Orientation: 1
XResolution: 72
YResolution: 72
ResolutionUnit: ‘Inch’
DateTime: ‘2011:11:11 21:07:46 ‘
YCbCrPositioning: ‘Co-sited’
DigitalCamera: [1×1 struct]
UnknownTags: [1×1 struct]
ExifThumbnail: [1×1 struct]
And then I get this error message:
??? Index exceeds matrix dimensions.
Error in ==> ind2rgb at 27
r = zeros(size(a)); r(:) = cm(a,1);
Error in ==> DSP_LCK at 24
rgb = ind2rgb(X,map);
Some advice please? When I import my image using the imread function, I get a map with only zeros (map = []). I want the RGB components of the image, but cannot get them since this requires the picture’s colormap (which is empty). This is the code I’m using:
filename = uigetfile(‘*.*’);
[X, map] = imread(filename);
info = imfinfo(filename)
width = getfield(imfinfo(filename),’Width’)
height = getfield(imfinfo(filename),’Height’)
figure(‘Name’,’Display imported image’,’NumberTitle’,’off’);
image(X);
rgb = ind2rgb(X,map);
The info of the image is:
info =
Filename: ’11-11-11 (30).JPG’
FileModDate: ’11-Nov-2011 21:07:46′
FileSize: 4549123
Format: ‘jpg’
FormatVersion: ”
Width: 4320
Height: 2432
BitDepth: 24
ColorType: ‘truecolor’
FormatSignature: ”
NumberOfSamples: 3
CodingMethod: ‘Huffman’
CodingProcess: ‘Sequential’
Comment: {}
ImageDescription: ‘ ‘
Make: ‘SONY ‘
Model: ‘DSC-W350 ‘
Orientation: 1
XResolution: 72
YResolution: 72
ResolutionUnit: ‘Inch’
DateTime: ‘2011:11:11 21:07:46 ‘
YCbCrPositioning: ‘Co-sited’
DigitalCamera: [1×1 struct]
UnknownTags: [1×1 struct]
ExifThumbnail: [1×1 struct]
And then I get this error message:
??? Index exceeds matrix dimensions.
Error in ==> ind2rgb at 27
r = zeros(size(a)); r(:) = cm(a,1);
Error in ==> DSP_LCK at 24
rgb = ind2rgb(X,map);
Some advice please? digital image processing, rgb MATLAB Answers — New Questions
Displaying figure from function in MATLAB gui
Hello, I have this function that takes a value Val and returns a 3D plot of two curves z1 and z2 with a dotted red line where they intersect with Val.
function Plot(Val)
X = [0:0.5:5];
Y = [0:0.1:1];
[x,y] = meshgrid(X,Y);
z1 = [x.*y.*57.5];
z2 = [x.*y.*110];
figure(1)
surf(x,y,z1, ‘FaceAlpha’, 0.5)
colormap winter
shading interp
hold on
surf(x,y,z2, ‘FaceAlpha’, 0.5)
shading interp
xlim([0 5])
ylim([0 1])
zlim([0 450])
Xg = x(1,:);
Yg = y(:,1);
hold on
M1 = contour3(Xg, Yg, z1, [CharVal,CharVal], ‘–r’);
M2 = contour3(Xg, Yg, z2, [CharVal, CharVal], ‘–r’);
I’m trying to create an app in the MATLAB gui where I have a slider for Val and would be able to see the intersection point change in real time. I currently am trying to use just a numeric input field for the value, but I can’t get the figure to plot in my GUI.
% Button pushed function: ExecuteButton
function ExecuteButtonPushed(app, event)
CharVal = app.EffValueEditField.Value;
EnergyEff(CharVal);
plot(, ‘Parent’, app.UIAxes);
end
Inputting a value and clicking the ‘Execute’ button gives me the plot but outside of the GUI. Any help is appreciatedHello, I have this function that takes a value Val and returns a 3D plot of two curves z1 and z2 with a dotted red line where they intersect with Val.
function Plot(Val)
X = [0:0.5:5];
Y = [0:0.1:1];
[x,y] = meshgrid(X,Y);
z1 = [x.*y.*57.5];
z2 = [x.*y.*110];
figure(1)
surf(x,y,z1, ‘FaceAlpha’, 0.5)
colormap winter
shading interp
hold on
surf(x,y,z2, ‘FaceAlpha’, 0.5)
shading interp
xlim([0 5])
ylim([0 1])
zlim([0 450])
Xg = x(1,:);
Yg = y(:,1);
hold on
M1 = contour3(Xg, Yg, z1, [CharVal,CharVal], ‘–r’);
M2 = contour3(Xg, Yg, z2, [CharVal, CharVal], ‘–r’);
I’m trying to create an app in the MATLAB gui where I have a slider for Val and would be able to see the intersection point change in real time. I currently am trying to use just a numeric input field for the value, but I can’t get the figure to plot in my GUI.
% Button pushed function: ExecuteButton
function ExecuteButtonPushed(app, event)
CharVal = app.EffValueEditField.Value;
EnergyEff(CharVal);
plot(, ‘Parent’, app.UIAxes);
end
Inputting a value and clicking the ‘Execute’ button gives me the plot but outside of the GUI. Any help is appreciated Hello, I have this function that takes a value Val and returns a 3D plot of two curves z1 and z2 with a dotted red line where they intersect with Val.
function Plot(Val)
X = [0:0.5:5];
Y = [0:0.1:1];
[x,y] = meshgrid(X,Y);
z1 = [x.*y.*57.5];
z2 = [x.*y.*110];
figure(1)
surf(x,y,z1, ‘FaceAlpha’, 0.5)
colormap winter
shading interp
hold on
surf(x,y,z2, ‘FaceAlpha’, 0.5)
shading interp
xlim([0 5])
ylim([0 1])
zlim([0 450])
Xg = x(1,:);
Yg = y(:,1);
hold on
M1 = contour3(Xg, Yg, z1, [CharVal,CharVal], ‘–r’);
M2 = contour3(Xg, Yg, z2, [CharVal, CharVal], ‘–r’);
I’m trying to create an app in the MATLAB gui where I have a slider for Val and would be able to see the intersection point change in real time. I currently am trying to use just a numeric input field for the value, but I can’t get the figure to plot in my GUI.
% Button pushed function: ExecuteButton
function ExecuteButtonPushed(app, event)
CharVal = app.EffValueEditField.Value;
EnergyEff(CharVal);
plot(, ‘Parent’, app.UIAxes);
end
Inputting a value and clicking the ‘Execute’ button gives me the plot but outside of the GUI. Any help is appreciated gui, contour MATLAB Answers — New Questions