Tag Archives: matlab
Separate data to plot as multiple lines
It has been a while since I have touched matlab, and as such I can’t quite figure out how to solve this issue. Essentially, I have data being created to monitor a device. This data is in an excel sheet, and I have imported that excel sheet into matlab. The table is then parsed to only include certain data for creation of each plot. My problem is when plotting the table, which has multiple runs included. An example of such I will be including below:
run time var1
0 0 0
0 1 1
0 2 …
1 3 …
1 4 …
2 5 …
3 6 50
My question is how would I split this data so that I can plot each run as a seperate line on the same graph? So in this case, it would be a line plot showing the 4 runs (0-3) as separate lines, comparing time to the change in the variables. Thank you.It has been a while since I have touched matlab, and as such I can’t quite figure out how to solve this issue. Essentially, I have data being created to monitor a device. This data is in an excel sheet, and I have imported that excel sheet into matlab. The table is then parsed to only include certain data for creation of each plot. My problem is when plotting the table, which has multiple runs included. An example of such I will be including below:
run time var1
0 0 0
0 1 1
0 2 …
1 3 …
1 4 …
2 5 …
3 6 50
My question is how would I split this data so that I can plot each run as a seperate line on the same graph? So in this case, it would be a line plot showing the 4 runs (0-3) as separate lines, comparing time to the change in the variables. Thank you. It has been a while since I have touched matlab, and as such I can’t quite figure out how to solve this issue. Essentially, I have data being created to monitor a device. This data is in an excel sheet, and I have imported that excel sheet into matlab. The table is then parsed to only include certain data for creation of each plot. My problem is when plotting the table, which has multiple runs included. An example of such I will be including below:
run time var1
0 0 0
0 1 1
0 2 …
1 3 …
1 4 …
2 5 …
3 6 50
My question is how would I split this data so that I can plot each run as a seperate line on the same graph? So in this case, it would be a line plot showing the 4 runs (0-3) as separate lines, comparing time to the change in the variables. Thank you. plot, table MATLAB Answers — New Questions
IVI connection to Rigol DMM
Hi All… I have been attempting to connect a Rigol DM3068 DMM to Matlab. The driver from the manufacturer has been installed. I have spent many hours going down a rabbit hole of pages that links to more links, along with processes that leads to depreciated functions and errors. Below shows the current state of my attempts.
I’m now rather confused on the actual process. It would be ideal to find an example of how to generate the wrapper and link the driver to Matlab with current functions.
>> instrhwinfo
ans =
HardwareInfo with properties:
MATLABVersion: ‘9.14 (R2023a)’
SupportedInterfaces: {‘gpib’ ‘serial’ ‘serialport’ ‘tcpip’ ‘udp’ ‘visa’ ‘Bluetooth’ ‘i2c’ ‘spi’}
SupportedDrivers: {‘matlab’ ‘ivi’ ‘vxipnp’}
ToolboxName: ‘Instrument Control Toolbox’
ToolboxVersion: ‘4.8 (R2023a)’
>> ividriverlist
ans =
1×4 table
VendorDriver MATLABDriver IVIClass SupportedModels
____________ ____________ ________ _______________
1 "rgdm3068" "" "IVIDmm" {["DM3068"]}
>> configStore = iviconfigurationstore;
>> add(configStore,"HardwareAsset","myDMMHWAsset2","TCPIP0::192.168.1.120::INSTR");
>> add(configStore,"DriverSession","myDMMSession2","rgdm3068","myDMMHWAsset2");
>> add(configStore,"LogicalName","myDMM2","myDMMSession2");
>> commit(configStore);
>> dev = ividev("IviDMM2","myDMM2");
No ividev MATLAB drivers found for your hardware.
>> instrhwinfo(‘ivi’)
ans =
HardwareInfo with properties:
LogicalNames: {‘myDMM’ ‘myDMM2’}
Modules: {1×13 cell}
ConfigurationServerVersion: ‘1.7.0.12115’
ConfigurationStoreLocation: ‘C:ProgramDataIVI FoundationIVIIviConfigurationStore.xml’
IVIRootPath: ‘C:Program FilesIVI FoundationIVI’Hi All… I have been attempting to connect a Rigol DM3068 DMM to Matlab. The driver from the manufacturer has been installed. I have spent many hours going down a rabbit hole of pages that links to more links, along with processes that leads to depreciated functions and errors. Below shows the current state of my attempts.
I’m now rather confused on the actual process. It would be ideal to find an example of how to generate the wrapper and link the driver to Matlab with current functions.
>> instrhwinfo
ans =
HardwareInfo with properties:
MATLABVersion: ‘9.14 (R2023a)’
SupportedInterfaces: {‘gpib’ ‘serial’ ‘serialport’ ‘tcpip’ ‘udp’ ‘visa’ ‘Bluetooth’ ‘i2c’ ‘spi’}
SupportedDrivers: {‘matlab’ ‘ivi’ ‘vxipnp’}
ToolboxName: ‘Instrument Control Toolbox’
ToolboxVersion: ‘4.8 (R2023a)’
>> ividriverlist
ans =
1×4 table
VendorDriver MATLABDriver IVIClass SupportedModels
____________ ____________ ________ _______________
1 "rgdm3068" "" "IVIDmm" {["DM3068"]}
>> configStore = iviconfigurationstore;
>> add(configStore,"HardwareAsset","myDMMHWAsset2","TCPIP0::192.168.1.120::INSTR");
>> add(configStore,"DriverSession","myDMMSession2","rgdm3068","myDMMHWAsset2");
>> add(configStore,"LogicalName","myDMM2","myDMMSession2");
>> commit(configStore);
>> dev = ividev("IviDMM2","myDMM2");
No ividev MATLAB drivers found for your hardware.
>> instrhwinfo(‘ivi’)
ans =
HardwareInfo with properties:
LogicalNames: {‘myDMM’ ‘myDMM2’}
Modules: {1×13 cell}
ConfigurationServerVersion: ‘1.7.0.12115’
ConfigurationStoreLocation: ‘C:ProgramDataIVI FoundationIVIIviConfigurationStore.xml’
IVIRootPath: ‘C:Program FilesIVI FoundationIVI’ Hi All… I have been attempting to connect a Rigol DM3068 DMM to Matlab. The driver from the manufacturer has been installed. I have spent many hours going down a rabbit hole of pages that links to more links, along with processes that leads to depreciated functions and errors. Below shows the current state of my attempts.
I’m now rather confused on the actual process. It would be ideal to find an example of how to generate the wrapper and link the driver to Matlab with current functions.
>> instrhwinfo
ans =
HardwareInfo with properties:
MATLABVersion: ‘9.14 (R2023a)’
SupportedInterfaces: {‘gpib’ ‘serial’ ‘serialport’ ‘tcpip’ ‘udp’ ‘visa’ ‘Bluetooth’ ‘i2c’ ‘spi’}
SupportedDrivers: {‘matlab’ ‘ivi’ ‘vxipnp’}
ToolboxName: ‘Instrument Control Toolbox’
ToolboxVersion: ‘4.8 (R2023a)’
>> ividriverlist
ans =
1×4 table
VendorDriver MATLABDriver IVIClass SupportedModels
____________ ____________ ________ _______________
1 "rgdm3068" "" "IVIDmm" {["DM3068"]}
>> configStore = iviconfigurationstore;
>> add(configStore,"HardwareAsset","myDMMHWAsset2","TCPIP0::192.168.1.120::INSTR");
>> add(configStore,"DriverSession","myDMMSession2","rgdm3068","myDMMHWAsset2");
>> add(configStore,"LogicalName","myDMM2","myDMMSession2");
>> commit(configStore);
>> dev = ividev("IviDMM2","myDMM2");
No ividev MATLAB drivers found for your hardware.
>> instrhwinfo(‘ivi’)
ans =
HardwareInfo with properties:
LogicalNames: {‘myDMM’ ‘myDMM2’}
Modules: {1×13 cell}
ConfigurationServerVersion: ‘1.7.0.12115’
ConfigurationStoreLocation: ‘C:ProgramDataIVI FoundationIVIIviConfigurationStore.xml’
IVIRootPath: ‘C:Program FilesIVI FoundationIVI’ ivi, rigol, instrument toolbox MATLAB Answers — New Questions
converting string to num and table
I have a table containing string data that represents cyclone certain and uncertain tracks. Each cell in the table may contain multiple track numbers (seperated by a space), where the presence of ‘x’ beside a number indicates uncertainty in that track. For example, in tempData(7,1) = "30 25x", ’30’ is a certain track, and ’25’ is uncertain.
I need to write a code that parses each cell in a column of tempData, separates the track numbers and their uncertainty markers (‘x’), and outputs a (in this case) 4-column table for each column in tempData. The headers of the output table should be track1, uncert1, track2, uncert2, corresponding to the parsed tracks and their certainty indicators (marked by 0 or 1). If the input has 3 tracks, the then output table should have a 6 column table
Finally, I want to store each output table in a cell array marked by the varname of the input column (y98, y99, y20, etc), as I need to process over 200 columns in my original data.
I have attached a sample input (tempData) and output for the first coumn that i want (tempDataOut).
Thanks in advance.I have a table containing string data that represents cyclone certain and uncertain tracks. Each cell in the table may contain multiple track numbers (seperated by a space), where the presence of ‘x’ beside a number indicates uncertainty in that track. For example, in tempData(7,1) = "30 25x", ’30’ is a certain track, and ’25’ is uncertain.
I need to write a code that parses each cell in a column of tempData, separates the track numbers and their uncertainty markers (‘x’), and outputs a (in this case) 4-column table for each column in tempData. The headers of the output table should be track1, uncert1, track2, uncert2, corresponding to the parsed tracks and their certainty indicators (marked by 0 or 1). If the input has 3 tracks, the then output table should have a 6 column table
Finally, I want to store each output table in a cell array marked by the varname of the input column (y98, y99, y20, etc), as I need to process over 200 columns in my original data.
I have attached a sample input (tempData) and output for the first coumn that i want (tempDataOut).
Thanks in advance. I have a table containing string data that represents cyclone certain and uncertain tracks. Each cell in the table may contain multiple track numbers (seperated by a space), where the presence of ‘x’ beside a number indicates uncertainty in that track. For example, in tempData(7,1) = "30 25x", ’30’ is a certain track, and ’25’ is uncertain.
I need to write a code that parses each cell in a column of tempData, separates the track numbers and their uncertainty markers (‘x’), and outputs a (in this case) 4-column table for each column in tempData. The headers of the output table should be track1, uncert1, track2, uncert2, corresponding to the parsed tracks and their certainty indicators (marked by 0 or 1). If the input has 3 tracks, the then output table should have a 6 column table
Finally, I want to store each output table in a cell array marked by the varname of the input column (y98, y99, y20, etc), as I need to process over 200 columns in my original data.
I have attached a sample input (tempData) and output for the first coumn that i want (tempDataOut).
Thanks in advance. data process MATLAB Answers — New Questions
Can I generate code for STM32H7 Boards using the Embedded Coder Support Package?
Does MathWorks offer Support Packages for generating code using Embedded Coder for STM32H7 Boards?Does MathWorks offer Support Packages for generating code using Embedded Coder for STM32H7 Boards? Does MathWorks offer Support Packages for generating code using Embedded Coder for STM32H7 Boards? embedded, coder, stm32h7, stm32, stmicroelectronics MATLAB Answers — New Questions
plot magnitude data at location (x,y,z)
I can’t figure out how to plot magnitudes of a variable at different (x,y,z) locations. In effect, I need to plot a 4D plot, (x,y,z,value). I thought I’d be able to do a 3D plot and set the 4D as color scale or something like that, but I can’t figure how to do that.
Perhaps I’m over thinking this….but, I’d appreciate any help.
Thanks!
JorgeI can’t figure out how to plot magnitudes of a variable at different (x,y,z) locations. In effect, I need to plot a 4D plot, (x,y,z,value). I thought I’d be able to do a 3D plot and set the 4D as color scale or something like that, but I can’t figure how to do that.
Perhaps I’m over thinking this….but, I’d appreciate any help.
Thanks!
Jorge I can’t figure out how to plot magnitudes of a variable at different (x,y,z) locations. In effect, I need to plot a 4D plot, (x,y,z,value). I thought I’d be able to do a 3D plot and set the 4D as color scale or something like that, but I can’t figure how to do that.
Perhaps I’m over thinking this….but, I’d appreciate any help.
Thanks!
Jorge plotting, 3d plots MATLAB Answers — New Questions
Why do the results returned by calling the “simulate” function with a “creditDefaultCopula” object vary based on the order of the rows in the input data?
When using "creditDefaultCopula" from Risk Management Toolbox, why are simulation results different when the rows of the data input are in different order even with the same random seed for all simulations?When using "creditDefaultCopula" from Risk Management Toolbox, why are simulation results different when the rows of the data input are in different order even with the same random seed for all simulations? When using "creditDefaultCopula" from Risk Management Toolbox, why are simulation results different when the rows of the data input are in different order even with the same random seed for all simulations? creditdefaultcopula, simulation MATLAB Answers — New Questions
Failed Code generation information file doesnt exist.
Post Content Post Content code generation MATLAB Answers — New Questions
I need help on superimposition of plot.
Hi guys, so I took two sets of data of knee extension using two types of sensor which is IMU MPU 6050 and Biopac mechanomyography (MMG), we took it in a same period of time but when it comes to us saving the data, the data we obtain for both plot has different x-axis range. Can anyone please explain and teach me how to do it I would be very appreciate and thank you very muchHi guys, so I took two sets of data of knee extension using two types of sensor which is IMU MPU 6050 and Biopac mechanomyography (MMG), we took it in a same period of time but when it comes to us saving the data, the data we obtain for both plot has different x-axis range. Can anyone please explain and teach me how to do it I would be very appreciate and thank you very much Hi guys, so I took two sets of data of knee extension using two types of sensor which is IMU MPU 6050 and Biopac mechanomyography (MMG), we took it in a same period of time but when it comes to us saving the data, the data we obtain for both plot has different x-axis range. Can anyone please explain and teach me how to do it I would be very appreciate and thank you very much transferred MATLAB Answers — New Questions
What is the difference between the ways of Predict and PredictAndUpdateState to update the network?
Hi All,
I am testing a trained LSTM network to finish the prediction task. I have used prerdict() and PredicAndUpdateState() to do the prediction respectively. The codes for both ways are as follows respectively:
(1). Using predict ()
YTest=predict(trainedNet,XTest); % XTest is the complete test data, which is a numeric array with the size of [16 x 272].
(2). Using PredictAndUpdateState()
for i=1:size(XTest,2)
Xt=XTest(:,i); % One coloum of XTest is extracted as the inputs of this timestep.
[trainedNet,YTest(:,i)]=PredictAndUpdateState(trainedNet,Xt); % Use the inputs of this timestep to predict the outputs, and update the network.
end
The test performance of using PredictAndUpdateState() is much worse than using predict(). But I have heard that both predict() and PredictAndUpdateState() will update the state of the network between each prediction. So, I wonder why the performances of those two functions are so different, and what is the difference between the ways of predict() and PredictAndUpdateState() to update networks.
Any help will be appredicted. Thank you so much!Hi All,
I am testing a trained LSTM network to finish the prediction task. I have used prerdict() and PredicAndUpdateState() to do the prediction respectively. The codes for both ways are as follows respectively:
(1). Using predict ()
YTest=predict(trainedNet,XTest); % XTest is the complete test data, which is a numeric array with the size of [16 x 272].
(2). Using PredictAndUpdateState()
for i=1:size(XTest,2)
Xt=XTest(:,i); % One coloum of XTest is extracted as the inputs of this timestep.
[trainedNet,YTest(:,i)]=PredictAndUpdateState(trainedNet,Xt); % Use the inputs of this timestep to predict the outputs, and update the network.
end
The test performance of using PredictAndUpdateState() is much worse than using predict(). But I have heard that both predict() and PredictAndUpdateState() will update the state of the network between each prediction. So, I wonder why the performances of those two functions are so different, and what is the difference between the ways of predict() and PredictAndUpdateState() to update networks.
Any help will be appredicted. Thank you so much! Hi All,
I am testing a trained LSTM network to finish the prediction task. I have used prerdict() and PredicAndUpdateState() to do the prediction respectively. The codes for both ways are as follows respectively:
(1). Using predict ()
YTest=predict(trainedNet,XTest); % XTest is the complete test data, which is a numeric array with the size of [16 x 272].
(2). Using PredictAndUpdateState()
for i=1:size(XTest,2)
Xt=XTest(:,i); % One coloum of XTest is extracted as the inputs of this timestep.
[trainedNet,YTest(:,i)]=PredictAndUpdateState(trainedNet,Xt); % Use the inputs of this timestep to predict the outputs, and update the network.
end
The test performance of using PredictAndUpdateState() is much worse than using predict(). But I have heard that both predict() and PredictAndUpdateState() will update the state of the network between each prediction. So, I wonder why the performances of those two functions are so different, and what is the difference between the ways of predict() and PredictAndUpdateState() to update networks.
Any help will be appredicted. Thank you so much! lstm, predict, predictandupdatestate, prediction, deep learning MATLAB Answers — New Questions
Issues with looping in structure: variable in the name
I am loading one Excel spreadsheet with 11 tabs. The 11 tabs are named fl1, fl2,… fl11.
The spreadsheet is currently loaded into a structure named flight_data. I don’t like the way it is organized, so I want to create a 11 new structures: somename1, somename2,….somename11.
I think the code will show how I’m trying to structure my data. The goal is to have 11 strutures that look like this:
%my loop that doesn’t work
for i = 1:11
fpro(i).loc7.x = flight_data.fpro{i}(:,1)
end
%my structure setup
fpro(i).name = ‘Flight Profile {i}’;
fpro(i).loc7.x = flight_data.fl{i}(:,1)
fpro(i).loc9.x = flight_data.fl{i}(:,4)
fpro(i).loc10.x = flight_data.fl{i}(:,7)
fpro(i).loc7.y = flight_data.fl{i}(:,2)
fpro(i).loc9.y = flight_data.fl{i}(:,5)
fpro(i).loc10.y = flight_data.fl{i}(:,8)
fpro(i).loc7.z = flight_data.fl{i}(:,3)
fpro(i).loc9.z = flight_data.fl{i}(:,6)
fpro(i).loc10.z = flight_data.fl{i}(:,9)I am loading one Excel spreadsheet with 11 tabs. The 11 tabs are named fl1, fl2,… fl11.
The spreadsheet is currently loaded into a structure named flight_data. I don’t like the way it is organized, so I want to create a 11 new structures: somename1, somename2,….somename11.
I think the code will show how I’m trying to structure my data. The goal is to have 11 strutures that look like this:
%my loop that doesn’t work
for i = 1:11
fpro(i).loc7.x = flight_data.fpro{i}(:,1)
end
%my structure setup
fpro(i).name = ‘Flight Profile {i}’;
fpro(i).loc7.x = flight_data.fl{i}(:,1)
fpro(i).loc9.x = flight_data.fl{i}(:,4)
fpro(i).loc10.x = flight_data.fl{i}(:,7)
fpro(i).loc7.y = flight_data.fl{i}(:,2)
fpro(i).loc9.y = flight_data.fl{i}(:,5)
fpro(i).loc10.y = flight_data.fl{i}(:,8)
fpro(i).loc7.z = flight_data.fl{i}(:,3)
fpro(i).loc9.z = flight_data.fl{i}(:,6)
fpro(i).loc10.z = flight_data.fl{i}(:,9) I am loading one Excel spreadsheet with 11 tabs. The 11 tabs are named fl1, fl2,… fl11.
The spreadsheet is currently loaded into a structure named flight_data. I don’t like the way it is organized, so I want to create a 11 new structures: somename1, somename2,….somename11.
I think the code will show how I’m trying to structure my data. The goal is to have 11 strutures that look like this:
%my loop that doesn’t work
for i = 1:11
fpro(i).loc7.x = flight_data.fpro{i}(:,1)
end
%my structure setup
fpro(i).name = ‘Flight Profile {i}’;
fpro(i).loc7.x = flight_data.fl{i}(:,1)
fpro(i).loc9.x = flight_data.fl{i}(:,4)
fpro(i).loc10.x = flight_data.fl{i}(:,7)
fpro(i).loc7.y = flight_data.fl{i}(:,2)
fpro(i).loc9.y = flight_data.fl{i}(:,5)
fpro(i).loc10.y = flight_data.fl{i}(:,8)
fpro(i).loc7.z = flight_data.fl{i}(:,3)
fpro(i).loc9.z = flight_data.fl{i}(:,6)
fpro(i).loc10.z = flight_data.fl{i}(:,9) for, structures, sytax MATLAB Answers — New Questions
Getting error message when running Runge Kutta solution…
The code that produces the errors is below:
clc;
mass = 13.5;
Jx = 0.8244;
Jy = 1.135;
Jz = 1.759;
Jxz = 0.1204;
G = Jx*Jz-Jxz^2;
G1 = Jxz*(Jx – Jy + Jz)/G;
G2 = (Jz*(Jz-Jy)+Jxz^2)/G;
G3 = Jz/G;
G4 = Jxz/G;
G5 = (Jz-Jx)/Jy;
G6 = Jxz/Jy;
G7 = ((Jx-Jy)*Jx +Jxz^2)/G;
G8 = (Jx/G);
p = 0;
q = 0;
r = 0;
l = 0.0000;
m = 0.0000;
n = 0.0000;
tspan = [0 10];
%[t,q] = ode45(@(t,q) (G5*p*r-G6*(p^2-r^2)+m/Jy), tspan,0);
%plot(t,q);
%pdot = (G1*p*q-G2*q*r + G3*l+G4*n);
[t,p]=ode45(@(t,p) (G1*p*q – G2*q*r + G3*l + G4*n),[0 10], 0.1);
plot(t,p,’–r’);
disp(p);
disp(t);
[t,q] = ode45(@(t,r) (G5*p*r – G6*p*p – G6*r*r + m/Jy), [0 10],0);
plot(t,q,’–g’);
[t,r] = ode45(@(t,r) (G7*p*q – G1*q*r + G4*l + G8*n), [0 10],0);
plot(t,r,’–b’)
The output with the error messages follows:
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0
0.2500
0.5000
0.7500
1.0000
1.2500
1.5000
1.7500
2.0000
2.2500
2.5000
2.7500
3.0000
3.2500
3.5000
3.7500
4.0000
4.2500
4.5000
4.7500
5.0000
5.2500
5.5000
5.7500
6.0000
6.2500
6.5000
6.7500
7.0000
7.2500
7.5000
7.7500
8.0000
8.2500
8.5000
8.7500
9.0000
9.2500
9.5000
9.7500
10.0000
Error using *
Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows in the second matrix. To
perform elementwise multiplication, use ‘.*’.
Error in test>@(t,r)(G5*p*r-G6*p*p-G6*r*r+m/Jy) (line 30)
[t,q] = ode45(@(t,r) (G5*p*r – G6*p*p – G6*r*r + m/Jy), [0 10],0);
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in test (line 30)
[t,q] = ode45(@(t,r) (G5*p*r – G6*p*p – G6*r*r + m/Jy), [0 10],0);The code that produces the errors is below:
clc;
mass = 13.5;
Jx = 0.8244;
Jy = 1.135;
Jz = 1.759;
Jxz = 0.1204;
G = Jx*Jz-Jxz^2;
G1 = Jxz*(Jx – Jy + Jz)/G;
G2 = (Jz*(Jz-Jy)+Jxz^2)/G;
G3 = Jz/G;
G4 = Jxz/G;
G5 = (Jz-Jx)/Jy;
G6 = Jxz/Jy;
G7 = ((Jx-Jy)*Jx +Jxz^2)/G;
G8 = (Jx/G);
p = 0;
q = 0;
r = 0;
l = 0.0000;
m = 0.0000;
n = 0.0000;
tspan = [0 10];
%[t,q] = ode45(@(t,q) (G5*p*r-G6*(p^2-r^2)+m/Jy), tspan,0);
%plot(t,q);
%pdot = (G1*p*q-G2*q*r + G3*l+G4*n);
[t,p]=ode45(@(t,p) (G1*p*q – G2*q*r + G3*l + G4*n),[0 10], 0.1);
plot(t,p,’–r’);
disp(p);
disp(t);
[t,q] = ode45(@(t,r) (G5*p*r – G6*p*p – G6*r*r + m/Jy), [0 10],0);
plot(t,q,’–g’);
[t,r] = ode45(@(t,r) (G7*p*q – G1*q*r + G4*l + G8*n), [0 10],0);
plot(t,r,’–b’)
The output with the error messages follows:
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0
0.2500
0.5000
0.7500
1.0000
1.2500
1.5000
1.7500
2.0000
2.2500
2.5000
2.7500
3.0000
3.2500
3.5000
3.7500
4.0000
4.2500
4.5000
4.7500
5.0000
5.2500
5.5000
5.7500
6.0000
6.2500
6.5000
6.7500
7.0000
7.2500
7.5000
7.7500
8.0000
8.2500
8.5000
8.7500
9.0000
9.2500
9.5000
9.7500
10.0000
Error using *
Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows in the second matrix. To
perform elementwise multiplication, use ‘.*’.
Error in test>@(t,r)(G5*p*r-G6*p*p-G6*r*r+m/Jy) (line 30)
[t,q] = ode45(@(t,r) (G5*p*r – G6*p*p – G6*r*r + m/Jy), [0 10],0);
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in test (line 30)
[t,q] = ode45(@(t,r) (G5*p*r – G6*p*p – G6*r*r + m/Jy), [0 10],0); The code that produces the errors is below:
clc;
mass = 13.5;
Jx = 0.8244;
Jy = 1.135;
Jz = 1.759;
Jxz = 0.1204;
G = Jx*Jz-Jxz^2;
G1 = Jxz*(Jx – Jy + Jz)/G;
G2 = (Jz*(Jz-Jy)+Jxz^2)/G;
G3 = Jz/G;
G4 = Jxz/G;
G5 = (Jz-Jx)/Jy;
G6 = Jxz/Jy;
G7 = ((Jx-Jy)*Jx +Jxz^2)/G;
G8 = (Jx/G);
p = 0;
q = 0;
r = 0;
l = 0.0000;
m = 0.0000;
n = 0.0000;
tspan = [0 10];
%[t,q] = ode45(@(t,q) (G5*p*r-G6*(p^2-r^2)+m/Jy), tspan,0);
%plot(t,q);
%pdot = (G1*p*q-G2*q*r + G3*l+G4*n);
[t,p]=ode45(@(t,p) (G1*p*q – G2*q*r + G3*l + G4*n),[0 10], 0.1);
plot(t,p,’–r’);
disp(p);
disp(t);
[t,q] = ode45(@(t,r) (G5*p*r – G6*p*p – G6*r*r + m/Jy), [0 10],0);
plot(t,q,’–g’);
[t,r] = ode45(@(t,r) (G7*p*q – G1*q*r + G4*l + G8*n), [0 10],0);
plot(t,r,’–b’)
The output with the error messages follows:
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0
0.2500
0.5000
0.7500
1.0000
1.2500
1.5000
1.7500
2.0000
2.2500
2.5000
2.7500
3.0000
3.2500
3.5000
3.7500
4.0000
4.2500
4.5000
4.7500
5.0000
5.2500
5.5000
5.7500
6.0000
6.2500
6.5000
6.7500
7.0000
7.2500
7.5000
7.7500
8.0000
8.2500
8.5000
8.7500
9.0000
9.2500
9.5000
9.7500
10.0000
Error using *
Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows in the second matrix. To
perform elementwise multiplication, use ‘.*’.
Error in test>@(t,r)(G5*p*r-G6*p*p-G6*r*r+m/Jy) (line 30)
[t,q] = ode45(@(t,r) (G5*p*r – G6*p*p – G6*r*r + m/Jy), [0 10],0);
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in test (line 30)
[t,q] = ode45(@(t,r) (G5*p*r – G6*p*p – G6*r*r + m/Jy), [0 10],0); runge kutta 4, errors MATLAB Answers — New Questions
Why does MATLAB crash on Linux with “Inconsistency detected by ld.so: ../elf/dl-tls.c: 597: _dl_allocate_tls_init:”
When I run MATLAB R2021b on my Linux machine, it occasionally crashes. The following error message appears in the terminal or at the top of the resulting crash stack trace:
Inconsistency detected by ld.so: ../elf/dl-tls.c: 597: _dl_allocate_tls_init: Assertion `listp != NULL’ failed!
This crash primarily happens when I attempt to use Simulink for the first time after launching MATLAB.When I run MATLAB R2021b on my Linux machine, it occasionally crashes. The following error message appears in the terminal or at the top of the resulting crash stack trace:
Inconsistency detected by ld.so: ../elf/dl-tls.c: 597: _dl_allocate_tls_init: Assertion `listp != NULL’ failed!
This crash primarily happens when I attempt to use Simulink for the first time after launching MATLAB. When I run MATLAB R2021b on my Linux machine, it occasionally crashes. The following error message appears in the terminal or at the top of the resulting crash stack trace:
Inconsistency detected by ld.so: ../elf/dl-tls.c: 597: _dl_allocate_tls_init: Assertion `listp != NULL’ failed!
This crash primarily happens when I attempt to use Simulink for the first time after launching MATLAB. crash, libc, linux, glibc MATLAB Answers — New Questions
too many open files even after adding fclose within my for loop
As the title says, I am receiving an error saying I have too many open files. I did look into it (via MatlabCentral) and attempted to fix it by adding ‘fclose’ after each ‘fopen.’ I am adding my for loop below. I included the first line of my code (readmatrix), but did not include the lines defining the variables because there are too many. What am I doing wrong here?
Thanks.
m=readmatrix(‘vertebrae_points_idno.xlsx’);
%%did not include lines defining my variables%%
for i=1:length(m)
for j=1:length(m(:,1))
conversion=conversion_array(j);
%combines variables into matrices for saving and printing.
[c1,c2,c3,c4,c5,c6,c7]=matrix_combine(c1x(i,:),c1y(i,:),c2x(i,:),c2y(i,:),c3x(i,:),c3y(i,:),c4x(i,:),c4y(i,:),c5x(i,:),c5y(i,:),c6x(i,:),c6y(i,:),c7x(i,:),c7y(i,:));
%calculate centroids.
[c2_centroid,c3_centroid,c4_centroid,c5_centroid,c6_centroid,c7_centroid]=get_centroids(c2,c3,c4,c5,c6,c7);
%generate "ideal" arc
[line_x,line_y,x,y,C]=generate_arc(c2,c3,c4,c5,c6,c7);
%transpose for CircleFit
arc_xy=[line_x.’ line_y.’];
%gather points of circle from vertebral points
Par=CircleFit(arc_xy);
%generate actual arc and plot
[x2,y2,true_lord_angle]=generate_second_arc(c2,c7,Par);
%calculate distance between two arcs
[converted_curve_dist,converted_max_curve_dist]=get_curve_distance(x,y,x2,y2,conversion);
%calculates extension angles
[c1_c7_angle,c2_c7_angle,c2c3_tangent,c3c4_tangent,c4c5_tangent,c5c6_tangent,c6c7_tangent]=rotation_angles(line_x,line_y,c1,c2,c3,c4,c5,c6,c7);
%closes image so the program can create another image with centroids.
close all
%calculates SVA, determines type of kyphosis, plots centroids and C2-C7 centroid line.
[kyphosis_type,sva_axis]=kyphosis_sva_new(c7,c2_centroid,c3_centroid,c4_centroid,c5_centroid,c6_centroid,c7_centroid, conversion);
spine_data=[converted_curve_dist,converted_max_curve_dist,sva_axis,true_lord_angle,c1_c7_angle,c2_c7_angle];
opening_name=’spine_xray_data.txt’;
opening_name2=’translation_angles.txt’;
fid=fopen(opening_name,’w’);
fprintf(fid,’n %10ft %10.2ft %10.2ft %10.2ft %10.2ft %10.2ft %10.2ft %10st %10.4f’,…
sub_id, spine_data,kyphosis_type,conversion);
fclose(fid);
fid2=fopen(opening_name2,’w’);
fprintf(fid2,’n %10.4ft %10.4ft %10.4ft %10.4ft %10.4f’,…
c2c3_tangent,c3c4_tangent,c4c5_tangent,c5c6_tangent,c6c7_tangent);
fclose(fid2);
end
endAs the title says, I am receiving an error saying I have too many open files. I did look into it (via MatlabCentral) and attempted to fix it by adding ‘fclose’ after each ‘fopen.’ I am adding my for loop below. I included the first line of my code (readmatrix), but did not include the lines defining the variables because there are too many. What am I doing wrong here?
Thanks.
m=readmatrix(‘vertebrae_points_idno.xlsx’);
%%did not include lines defining my variables%%
for i=1:length(m)
for j=1:length(m(:,1))
conversion=conversion_array(j);
%combines variables into matrices for saving and printing.
[c1,c2,c3,c4,c5,c6,c7]=matrix_combine(c1x(i,:),c1y(i,:),c2x(i,:),c2y(i,:),c3x(i,:),c3y(i,:),c4x(i,:),c4y(i,:),c5x(i,:),c5y(i,:),c6x(i,:),c6y(i,:),c7x(i,:),c7y(i,:));
%calculate centroids.
[c2_centroid,c3_centroid,c4_centroid,c5_centroid,c6_centroid,c7_centroid]=get_centroids(c2,c3,c4,c5,c6,c7);
%generate "ideal" arc
[line_x,line_y,x,y,C]=generate_arc(c2,c3,c4,c5,c6,c7);
%transpose for CircleFit
arc_xy=[line_x.’ line_y.’];
%gather points of circle from vertebral points
Par=CircleFit(arc_xy);
%generate actual arc and plot
[x2,y2,true_lord_angle]=generate_second_arc(c2,c7,Par);
%calculate distance between two arcs
[converted_curve_dist,converted_max_curve_dist]=get_curve_distance(x,y,x2,y2,conversion);
%calculates extension angles
[c1_c7_angle,c2_c7_angle,c2c3_tangent,c3c4_tangent,c4c5_tangent,c5c6_tangent,c6c7_tangent]=rotation_angles(line_x,line_y,c1,c2,c3,c4,c5,c6,c7);
%closes image so the program can create another image with centroids.
close all
%calculates SVA, determines type of kyphosis, plots centroids and C2-C7 centroid line.
[kyphosis_type,sva_axis]=kyphosis_sva_new(c7,c2_centroid,c3_centroid,c4_centroid,c5_centroid,c6_centroid,c7_centroid, conversion);
spine_data=[converted_curve_dist,converted_max_curve_dist,sva_axis,true_lord_angle,c1_c7_angle,c2_c7_angle];
opening_name=’spine_xray_data.txt’;
opening_name2=’translation_angles.txt’;
fid=fopen(opening_name,’w’);
fprintf(fid,’n %10ft %10.2ft %10.2ft %10.2ft %10.2ft %10.2ft %10.2ft %10st %10.4f’,…
sub_id, spine_data,kyphosis_type,conversion);
fclose(fid);
fid2=fopen(opening_name2,’w’);
fprintf(fid2,’n %10.4ft %10.4ft %10.4ft %10.4ft %10.4f’,…
c2c3_tangent,c3c4_tangent,c4c5_tangent,c5c6_tangent,c6c7_tangent);
fclose(fid2);
end
end As the title says, I am receiving an error saying I have too many open files. I did look into it (via MatlabCentral) and attempted to fix it by adding ‘fclose’ after each ‘fopen.’ I am adding my for loop below. I included the first line of my code (readmatrix), but did not include the lines defining the variables because there are too many. What am I doing wrong here?
Thanks.
m=readmatrix(‘vertebrae_points_idno.xlsx’);
%%did not include lines defining my variables%%
for i=1:length(m)
for j=1:length(m(:,1))
conversion=conversion_array(j);
%combines variables into matrices for saving and printing.
[c1,c2,c3,c4,c5,c6,c7]=matrix_combine(c1x(i,:),c1y(i,:),c2x(i,:),c2y(i,:),c3x(i,:),c3y(i,:),c4x(i,:),c4y(i,:),c5x(i,:),c5y(i,:),c6x(i,:),c6y(i,:),c7x(i,:),c7y(i,:));
%calculate centroids.
[c2_centroid,c3_centroid,c4_centroid,c5_centroid,c6_centroid,c7_centroid]=get_centroids(c2,c3,c4,c5,c6,c7);
%generate "ideal" arc
[line_x,line_y,x,y,C]=generate_arc(c2,c3,c4,c5,c6,c7);
%transpose for CircleFit
arc_xy=[line_x.’ line_y.’];
%gather points of circle from vertebral points
Par=CircleFit(arc_xy);
%generate actual arc and plot
[x2,y2,true_lord_angle]=generate_second_arc(c2,c7,Par);
%calculate distance between two arcs
[converted_curve_dist,converted_max_curve_dist]=get_curve_distance(x,y,x2,y2,conversion);
%calculates extension angles
[c1_c7_angle,c2_c7_angle,c2c3_tangent,c3c4_tangent,c4c5_tangent,c5c6_tangent,c6c7_tangent]=rotation_angles(line_x,line_y,c1,c2,c3,c4,c5,c6,c7);
%closes image so the program can create another image with centroids.
close all
%calculates SVA, determines type of kyphosis, plots centroids and C2-C7 centroid line.
[kyphosis_type,sva_axis]=kyphosis_sva_new(c7,c2_centroid,c3_centroid,c4_centroid,c5_centroid,c6_centroid,c7_centroid, conversion);
spine_data=[converted_curve_dist,converted_max_curve_dist,sva_axis,true_lord_angle,c1_c7_angle,c2_c7_angle];
opening_name=’spine_xray_data.txt’;
opening_name2=’translation_angles.txt’;
fid=fopen(opening_name,’w’);
fprintf(fid,’n %10ft %10.2ft %10.2ft %10.2ft %10.2ft %10.2ft %10.2ft %10st %10.4f’,…
sub_id, spine_data,kyphosis_type,conversion);
fclose(fid);
fid2=fopen(opening_name2,’w’);
fprintf(fid2,’n %10.4ft %10.4ft %10.4ft %10.4ft %10.4f’,…
c2c3_tangent,c3c4_tangent,c4c5_tangent,c5c6_tangent,c6c7_tangent);
fclose(fid2);
end
end error, fclose, fopen MATLAB Answers — New Questions
are there motor resolver models out there?
Has anyone modeled a dc motor and resolver in multibody or other? Looking for an example rather brute force attempting including learning curve.Has anyone modeled a dc motor and resolver in multibody or other? Looking for an example rather brute force attempting including learning curve. Has anyone modeled a dc motor and resolver in multibody or other? Looking for an example rather brute force attempting including learning curve. resolver MATLAB Answers — New Questions
Don’t understand the reason this code is giving me errors.
The code that is producing the error is below. It says:
>> test
Error: File: test.m Line: 32 Column: 58
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.
>> test
Error: File: test.m Line: 30 Column: 60
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.
Code that produces errors is below.
clc;
mass = 13.5;
Jx = 0.8244;
Jy = 1.135;
Jz = 1.759;
Jxz = 0.1204;
G = Jx*Jz-Jxz^2;
G1 = Jxz*(Jx – Jy + Jz)/G;
G2 = (Jz*(Jz-Jy)+Jxz^2)/G;
G3 = Jz/G;
G4 = Jxz/G;
G5 = (Jz-Jx)/Jy;
G6 = Jxz/Jy;
G7 = ((Jx-Jy)*Jx +Jxz^2)/G;
G8 = (Jx/G);
p = 0;
q = 0;
r = 0;
l = 0.0000;
m = 0.0000;
n = 0.0000;
tspan = [0 10];
%[t,q] = ode45(@(t,q) (G5*p*r-G6*(p^2-r^2)+m/Jy), tspan,0);
%plot(t,q);
%pdot = (G1*p*q-G2*q*r + G3*l+G4*n);
[t,p]=ode45(@(t,p) (G1*p*q-G2*q*r+G3*l+G4*n),[0 10], 0.1);
plot(t,p,’–r’);
disp(p);
disp(t);
[t,q] = ode45(@(t,r) (G5*p*r-G6*p*p-G6*r*r)+m/Jy), [0 10],0);
plot(t,q,’–g’);
[t,r] = ode45(@(t,r) (G7*p*q-G1*q*r + G4*l+G8*n), [0 10],0);
plot(t,r,’–b’)The code that is producing the error is below. It says:
>> test
Error: File: test.m Line: 32 Column: 58
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.
>> test
Error: File: test.m Line: 30 Column: 60
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.
Code that produces errors is below.
clc;
mass = 13.5;
Jx = 0.8244;
Jy = 1.135;
Jz = 1.759;
Jxz = 0.1204;
G = Jx*Jz-Jxz^2;
G1 = Jxz*(Jx – Jy + Jz)/G;
G2 = (Jz*(Jz-Jy)+Jxz^2)/G;
G3 = Jz/G;
G4 = Jxz/G;
G5 = (Jz-Jx)/Jy;
G6 = Jxz/Jy;
G7 = ((Jx-Jy)*Jx +Jxz^2)/G;
G8 = (Jx/G);
p = 0;
q = 0;
r = 0;
l = 0.0000;
m = 0.0000;
n = 0.0000;
tspan = [0 10];
%[t,q] = ode45(@(t,q) (G5*p*r-G6*(p^2-r^2)+m/Jy), tspan,0);
%plot(t,q);
%pdot = (G1*p*q-G2*q*r + G3*l+G4*n);
[t,p]=ode45(@(t,p) (G1*p*q-G2*q*r+G3*l+G4*n),[0 10], 0.1);
plot(t,p,’–r’);
disp(p);
disp(t);
[t,q] = ode45(@(t,r) (G5*p*r-G6*p*p-G6*r*r)+m/Jy), [0 10],0);
plot(t,q,’–g’);
[t,r] = ode45(@(t,r) (G7*p*q-G1*q*r + G4*l+G8*n), [0 10],0);
plot(t,r,’–b’) The code that is producing the error is below. It says:
>> test
Error: File: test.m Line: 32 Column: 58
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.
>> test
Error: File: test.m Line: 30 Column: 60
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.
Code that produces errors is below.
clc;
mass = 13.5;
Jx = 0.8244;
Jy = 1.135;
Jz = 1.759;
Jxz = 0.1204;
G = Jx*Jz-Jxz^2;
G1 = Jxz*(Jx – Jy + Jz)/G;
G2 = (Jz*(Jz-Jy)+Jxz^2)/G;
G3 = Jz/G;
G4 = Jxz/G;
G5 = (Jz-Jx)/Jy;
G6 = Jxz/Jy;
G7 = ((Jx-Jy)*Jx +Jxz^2)/G;
G8 = (Jx/G);
p = 0;
q = 0;
r = 0;
l = 0.0000;
m = 0.0000;
n = 0.0000;
tspan = [0 10];
%[t,q] = ode45(@(t,q) (G5*p*r-G6*(p^2-r^2)+m/Jy), tspan,0);
%plot(t,q);
%pdot = (G1*p*q-G2*q*r + G3*l+G4*n);
[t,p]=ode45(@(t,p) (G1*p*q-G2*q*r+G3*l+G4*n),[0 10], 0.1);
plot(t,p,’–r’);
disp(p);
disp(t);
[t,q] = ode45(@(t,r) (G5*p*r-G6*p*p-G6*r*r)+m/Jy), [0 10],0);
plot(t,q,’–g’);
[t,r] = ode45(@(t,r) (G7*p*q-G1*q*r + G4*l+G8*n), [0 10],0);
plot(t,r,’–b’) error in calling runge kutta 4 function. MATLAB Answers — New Questions
Bus selector cannot find signals where the name has been changed programmatically?
Hi,
I programmatically need to change signal names in simulink.
I use a code similar to:
lineH = find_system(gcs, ‘FindAll’, ‘on’, ‘type’, ‘line’);
set(lineH, ‘Name’, ‘NewName’);
So far so good, but when the changed signal is fed into a bus and should then be selected with a bus selector block, the selector block does not find the "NewName".
I would need to manually open the bus selector block and select the "NewName". Problem is, that there are hundrets of signals to be changed and even much more bus selectors, where the change needs then to be done manually.
Interresting is, that if a signal name change in Simulink is done manually, the bus selectors are somehow updated and the "NewName" is detected automatically without the need of selecting the signal in the respective bus selectors.
Has anyone a solution for this problem?
It would be nice, if there was a built in matlab/simulink function that can automatically update all bus selectors after a programmatically performed signal name change?
Thanks for you help.
ThomasHi,
I programmatically need to change signal names in simulink.
I use a code similar to:
lineH = find_system(gcs, ‘FindAll’, ‘on’, ‘type’, ‘line’);
set(lineH, ‘Name’, ‘NewName’);
So far so good, but when the changed signal is fed into a bus and should then be selected with a bus selector block, the selector block does not find the "NewName".
I would need to manually open the bus selector block and select the "NewName". Problem is, that there are hundrets of signals to be changed and even much more bus selectors, where the change needs then to be done manually.
Interresting is, that if a signal name change in Simulink is done manually, the bus selectors are somehow updated and the "NewName" is detected automatically without the need of selecting the signal in the respective bus selectors.
Has anyone a solution for this problem?
It would be nice, if there was a built in matlab/simulink function that can automatically update all bus selectors after a programmatically performed signal name change?
Thanks for you help.
Thomas Hi,
I programmatically need to change signal names in simulink.
I use a code similar to:
lineH = find_system(gcs, ‘FindAll’, ‘on’, ‘type’, ‘line’);
set(lineH, ‘Name’, ‘NewName’);
So far so good, but when the changed signal is fed into a bus and should then be selected with a bus selector block, the selector block does not find the "NewName".
I would need to manually open the bus selector block and select the "NewName". Problem is, that there are hundrets of signals to be changed and even much more bus selectors, where the change needs then to be done manually.
Interresting is, that if a signal name change in Simulink is done manually, the bus selectors are somehow updated and the "NewName" is detected automatically without the need of selecting the signal in the respective bus selectors.
Has anyone a solution for this problem?
It would be nice, if there was a built in matlab/simulink function that can automatically update all bus selectors after a programmatically performed signal name change?
Thanks for you help.
Thomas busselector, bus selector, programmatically, signal name change programmatically, signal name change, programmatically change simulink signal name, signal name change with m script MATLAB Answers — New Questions
Converting cell array with elements to numerical or double matrix
I have to import a cell array that is composed of strings and numbers from excel to MATLAB using readcell, and one part of the larger input data that is of interest to me is an array with mostly numbers, and otherwise some strings in the first column and empty spaces in the numerical section that appear as <missing>. Usually, I used to do this using xlsread, but due to the increasing pressure by MATLAB to use its more specific functions for such operations, and also as it seems like the readcell function DOES work faster, I am trying to get familiar with readcell here.
I would like to treat the particular section of interest as a table with a numerical array, and it would be OK for me to e.g. convert the <missing> elements to number 0 in my final numerical matrix. Also keep in my mind that this section is just a small part of a much larger data file, and using readtable will not work.
Below is the code:
clc
InputData=readcell(‘MATLAB_readcell.xlsx’,"Sheet","Sample Data")
InputString=string(InputData)
Numbers=InputString(:,2:end)
[ii,jj]=find(ismissing(Numbers))
Numbers(ii,jj)=’0′
But here I have a problem: So far I can only convert the input to a string first, then look for <missing> in the resulting string array using ismissing, then replace those elements with a string zeor (as ‘0’), then convert the whole thing to a numerical array using str2num.
First of all, I assume there must be an easier way to do this, but regardless of that, the resulting numerical matrix here has saome faults, in that all the vales that appear as 70 in the string array, are equal to 0 in final matrix. In other words, although I want the program to only set the string value of every <missing> element with in particular ii&jj posiztion, it actually sets the whole row equal to ‘0’.
is there an easier way to do this and if not, how can I at least solve the problem with the faulty rows?I have to import a cell array that is composed of strings and numbers from excel to MATLAB using readcell, and one part of the larger input data that is of interest to me is an array with mostly numbers, and otherwise some strings in the first column and empty spaces in the numerical section that appear as <missing>. Usually, I used to do this using xlsread, but due to the increasing pressure by MATLAB to use its more specific functions for such operations, and also as it seems like the readcell function DOES work faster, I am trying to get familiar with readcell here.
I would like to treat the particular section of interest as a table with a numerical array, and it would be OK for me to e.g. convert the <missing> elements to number 0 in my final numerical matrix. Also keep in my mind that this section is just a small part of a much larger data file, and using readtable will not work.
Below is the code:
clc
InputData=readcell(‘MATLAB_readcell.xlsx’,"Sheet","Sample Data")
InputString=string(InputData)
Numbers=InputString(:,2:end)
[ii,jj]=find(ismissing(Numbers))
Numbers(ii,jj)=’0′
But here I have a problem: So far I can only convert the input to a string first, then look for <missing> in the resulting string array using ismissing, then replace those elements with a string zeor (as ‘0’), then convert the whole thing to a numerical array using str2num.
First of all, I assume there must be an easier way to do this, but regardless of that, the resulting numerical matrix here has saome faults, in that all the vales that appear as 70 in the string array, are equal to 0 in final matrix. In other words, although I want the program to only set the string value of every <missing> element with in particular ii&jj posiztion, it actually sets the whole row equal to ‘0’.
is there an easier way to do this and if not, how can I at least solve the problem with the faulty rows? I have to import a cell array that is composed of strings and numbers from excel to MATLAB using readcell, and one part of the larger input data that is of interest to me is an array with mostly numbers, and otherwise some strings in the first column and empty spaces in the numerical section that appear as <missing>. Usually, I used to do this using xlsread, but due to the increasing pressure by MATLAB to use its more specific functions for such operations, and also as it seems like the readcell function DOES work faster, I am trying to get familiar with readcell here.
I would like to treat the particular section of interest as a table with a numerical array, and it would be OK for me to e.g. convert the <missing> elements to number 0 in my final numerical matrix. Also keep in my mind that this section is just a small part of a much larger data file, and using readtable will not work.
Below is the code:
clc
InputData=readcell(‘MATLAB_readcell.xlsx’,"Sheet","Sample Data")
InputString=string(InputData)
Numbers=InputString(:,2:end)
[ii,jj]=find(ismissing(Numbers))
Numbers(ii,jj)=’0′
But here I have a problem: So far I can only convert the input to a string first, then look for <missing> in the resulting string array using ismissing, then replace those elements with a string zeor (as ‘0’), then convert the whole thing to a numerical array using str2num.
First of all, I assume there must be an easier way to do this, but regardless of that, the resulting numerical matrix here has saome faults, in that all the vales that appear as 70 in the string array, are equal to 0 in final matrix. In other words, although I want the program to only set the string value of every <missing> element with in particular ii&jj posiztion, it actually sets the whole row equal to ‘0’.
is there an easier way to do this and if not, how can I at least solve the problem with the faulty rows? readcell, str2num, reading cells, xlsread, excel input, string arrays, missing MATLAB Answers — New Questions
为什么我会收到”BLAS 加载错误: C:MATLAB7binwin32atlas_Athlon.dll: 找不到指定的模块。”,我下载的是Matlab2024a(D盘中),以前下载过另一款MATLAB(C盘)但删除了
clear
m0=1;
lamda=532*10^(-9);%lamda=[417,457,488,532,632.8]*10^(-9); %光束波长
z=50;%z=eps+[0:5:50]; %传播距离
R=0.03;%接受孔径的半径
A0=10;%光束功率常数
det=0.01:0.01:0.15; %横向相干长度
L=[1,5,10,20,30];%光总数指数
e=1*10^(-5);%e=[0.01,0.1,1,10,100]*10^(-5);%动能耗散率
X=1*10^(-8);% 温度耗5散
eta=0.001;% 内尺度因子
abc=3;%各项异性子
gama=-3;%温度盐度贡献比
NUM=10;
m=m0-NUM:1:m0+NUM;
k=2*pi/lamda;
for iiii=1:length(L)
C0=0;
for ll=1:L(iiii)
C0=C0+factorial(L(iiii))/factorial(ll)/factorial(L(iiii)-ll)*(-1)^(ll-1)/ll;
end
for iii=1:length(det)
for ii=1:length(m)
qtemp=0;
funt1=pi^2/(k*z)*(factorial(m0)*A0)^2/C0;
rouc2=8.705*10^(-8)*k^2*(e*eta)^(-1/3)*abc^(-2)*X*z*(1-2.605*gama^(-1)+7.007*gama^(-2));
for lll=1:L(iiii)
funt2=factorial(L(iiii))/(factorial(lll)*factorial(L(iiii)-lll))*(-1)^(lll-1)/lll;
fun=@(r) r.*funt1.*funt2.*(besselj(m0./2,k./4./z.*r.^2)).^2.*exp(-r.^2*(1./(lll.*det(iii).^2)+2.*rouc2))…
.*besseli(m(ii)-m0,(1./(lll.*det(iii).^2)+2.*rouc2).*r.^2);
qtemp=qtemp+integral(fun,0,R);
end
q(ii)=qtemp;
end
P(iiii,iii)=q(NUM+1)/sum(q);
end
end
figure
plot(det,P(1,:),’rs-‘);hold on
plot(det,P(2,:),’b+-‘);hold on
plot(det,P(3,:),’c*-‘);hold on
plot(det,P(4,:),’md-‘);hold on
plot(det,P(5,:),’g^-‘);
legend(‘L=1′,’L=5′,’L=10′,’L=20′,’L=30’)
%legend(‘λ=417nm’,’λ=457nm’,’λ=488nm’,’λ=532nm’,’λ=632.8nm’)
%legend(‘e=10^{-5}’,’e=3*10^{-5}’,’e=5*10^{-5}’,’e=7*10^{-5}’,’e=9*10^{-5}’)
xlabel(‘delta/m’);ylabel(‘P_{l_{0}}’);
axis([0.01,0.15,0.35,0.85]);hold on
demo1 = 0.35:0.1:0.85;
demo2 = [0.01,0.03,0.06,0.09,0.12,0.15];%demo2 = 0.01:0.02:0.1;
set(gca,’yTick’,demo1)
set(gca,’xTick’,demo2)
%xlabel(‘delta/m’);ylabel(‘P_{l_{0}}’);
%axis([0.01,0.1,0.35,0.85]);hold on
%demo1 = 0.35:0.1:0.85;
%demo2 = 0.01:0.02:0.1;
%set(gca,’yTick’,demo1)
%set(gca,’xTick’,demo2)
% [X0,Y0] = meshgrid(lamda,det);
% figure,surf(X0,Y0,P)
% %figure,bar3(P)
% xlabel(‘lamda’);ylabel(‘det’);zlabel(‘P_{m_{0}}’);hold on
>> MHBew_beamindex_hengxiangxiangganchagndu
BLAS: trying environment BLAS_VERSION…
BLAS: loading C:MATLAB7binwin32atlas_Athlon.dll
BLAS: unloading libraries
错误使用 *
BLAS 加载错误:
C:MATLAB7binwin32atlas_Athlon.dll: 找不到指定的模块。
出错 integralCalc>iterateScalarValued (第 330 行)
x = NODES*halfh + midpt; % NNODES x nsubs
出错 integralCalc>vadapt (第 148 行)
[q,errbnd] = iterateScalarValued(u,tinterval,pathlen, …
出错 integralCalc (第 77 行)
[q,errbnd] = vadapt(vfunAB,interval, …
出错 integral (第 87 行)
Q = integralCalc(fun,a,b,opstruct);
出错 MHBew_beamindex_hengxiangxiangganchagndu (第 36 行)
qtemp=qtemp+integral(fun,0,R);clear
m0=1;
lamda=532*10^(-9);%lamda=[417,457,488,532,632.8]*10^(-9); %光束波长
z=50;%z=eps+[0:5:50]; %传播距离
R=0.03;%接受孔径的半径
A0=10;%光束功率常数
det=0.01:0.01:0.15; %横向相干长度
L=[1,5,10,20,30];%光总数指数
e=1*10^(-5);%e=[0.01,0.1,1,10,100]*10^(-5);%动能耗散率
X=1*10^(-8);% 温度耗5散
eta=0.001;% 内尺度因子
abc=3;%各项异性子
gama=-3;%温度盐度贡献比
NUM=10;
m=m0-NUM:1:m0+NUM;
k=2*pi/lamda;
for iiii=1:length(L)
C0=0;
for ll=1:L(iiii)
C0=C0+factorial(L(iiii))/factorial(ll)/factorial(L(iiii)-ll)*(-1)^(ll-1)/ll;
end
for iii=1:length(det)
for ii=1:length(m)
qtemp=0;
funt1=pi^2/(k*z)*(factorial(m0)*A0)^2/C0;
rouc2=8.705*10^(-8)*k^2*(e*eta)^(-1/3)*abc^(-2)*X*z*(1-2.605*gama^(-1)+7.007*gama^(-2));
for lll=1:L(iiii)
funt2=factorial(L(iiii))/(factorial(lll)*factorial(L(iiii)-lll))*(-1)^(lll-1)/lll;
fun=@(r) r.*funt1.*funt2.*(besselj(m0./2,k./4./z.*r.^2)).^2.*exp(-r.^2*(1./(lll.*det(iii).^2)+2.*rouc2))…
.*besseli(m(ii)-m0,(1./(lll.*det(iii).^2)+2.*rouc2).*r.^2);
qtemp=qtemp+integral(fun,0,R);
end
q(ii)=qtemp;
end
P(iiii,iii)=q(NUM+1)/sum(q);
end
end
figure
plot(det,P(1,:),’rs-‘);hold on
plot(det,P(2,:),’b+-‘);hold on
plot(det,P(3,:),’c*-‘);hold on
plot(det,P(4,:),’md-‘);hold on
plot(det,P(5,:),’g^-‘);
legend(‘L=1′,’L=5′,’L=10′,’L=20′,’L=30’)
%legend(‘λ=417nm’,’λ=457nm’,’λ=488nm’,’λ=532nm’,’λ=632.8nm’)
%legend(‘e=10^{-5}’,’e=3*10^{-5}’,’e=5*10^{-5}’,’e=7*10^{-5}’,’e=9*10^{-5}’)
xlabel(‘delta/m’);ylabel(‘P_{l_{0}}’);
axis([0.01,0.15,0.35,0.85]);hold on
demo1 = 0.35:0.1:0.85;
demo2 = [0.01,0.03,0.06,0.09,0.12,0.15];%demo2 = 0.01:0.02:0.1;
set(gca,’yTick’,demo1)
set(gca,’xTick’,demo2)
%xlabel(‘delta/m’);ylabel(‘P_{l_{0}}’);
%axis([0.01,0.1,0.35,0.85]);hold on
%demo1 = 0.35:0.1:0.85;
%demo2 = 0.01:0.02:0.1;
%set(gca,’yTick’,demo1)
%set(gca,’xTick’,demo2)
% [X0,Y0] = meshgrid(lamda,det);
% figure,surf(X0,Y0,P)
% %figure,bar3(P)
% xlabel(‘lamda’);ylabel(‘det’);zlabel(‘P_{m_{0}}’);hold on
>> MHBew_beamindex_hengxiangxiangganchagndu
BLAS: trying environment BLAS_VERSION…
BLAS: loading C:MATLAB7binwin32atlas_Athlon.dll
BLAS: unloading libraries
错误使用 *
BLAS 加载错误:
C:MATLAB7binwin32atlas_Athlon.dll: 找不到指定的模块。
出错 integralCalc>iterateScalarValued (第 330 行)
x = NODES*halfh + midpt; % NNODES x nsubs
出错 integralCalc>vadapt (第 148 行)
[q,errbnd] = iterateScalarValued(u,tinterval,pathlen, …
出错 integralCalc (第 77 行)
[q,errbnd] = vadapt(vfunAB,interval, …
出错 integral (第 87 行)
Q = integralCalc(fun,a,b,opstruct);
出错 MHBew_beamindex_hengxiangxiangganchagndu (第 36 行)
qtemp=qtemp+integral(fun,0,R); clear
m0=1;
lamda=532*10^(-9);%lamda=[417,457,488,532,632.8]*10^(-9); %光束波长
z=50;%z=eps+[0:5:50]; %传播距离
R=0.03;%接受孔径的半径
A0=10;%光束功率常数
det=0.01:0.01:0.15; %横向相干长度
L=[1,5,10,20,30];%光总数指数
e=1*10^(-5);%e=[0.01,0.1,1,10,100]*10^(-5);%动能耗散率
X=1*10^(-8);% 温度耗5散
eta=0.001;% 内尺度因子
abc=3;%各项异性子
gama=-3;%温度盐度贡献比
NUM=10;
m=m0-NUM:1:m0+NUM;
k=2*pi/lamda;
for iiii=1:length(L)
C0=0;
for ll=1:L(iiii)
C0=C0+factorial(L(iiii))/factorial(ll)/factorial(L(iiii)-ll)*(-1)^(ll-1)/ll;
end
for iii=1:length(det)
for ii=1:length(m)
qtemp=0;
funt1=pi^2/(k*z)*(factorial(m0)*A0)^2/C0;
rouc2=8.705*10^(-8)*k^2*(e*eta)^(-1/3)*abc^(-2)*X*z*(1-2.605*gama^(-1)+7.007*gama^(-2));
for lll=1:L(iiii)
funt2=factorial(L(iiii))/(factorial(lll)*factorial(L(iiii)-lll))*(-1)^(lll-1)/lll;
fun=@(r) r.*funt1.*funt2.*(besselj(m0./2,k./4./z.*r.^2)).^2.*exp(-r.^2*(1./(lll.*det(iii).^2)+2.*rouc2))…
.*besseli(m(ii)-m0,(1./(lll.*det(iii).^2)+2.*rouc2).*r.^2);
qtemp=qtemp+integral(fun,0,R);
end
q(ii)=qtemp;
end
P(iiii,iii)=q(NUM+1)/sum(q);
end
end
figure
plot(det,P(1,:),’rs-‘);hold on
plot(det,P(2,:),’b+-‘);hold on
plot(det,P(3,:),’c*-‘);hold on
plot(det,P(4,:),’md-‘);hold on
plot(det,P(5,:),’g^-‘);
legend(‘L=1′,’L=5′,’L=10′,’L=20′,’L=30’)
%legend(‘λ=417nm’,’λ=457nm’,’λ=488nm’,’λ=532nm’,’λ=632.8nm’)
%legend(‘e=10^{-5}’,’e=3*10^{-5}’,’e=5*10^{-5}’,’e=7*10^{-5}’,’e=9*10^{-5}’)
xlabel(‘delta/m’);ylabel(‘P_{l_{0}}’);
axis([0.01,0.15,0.35,0.85]);hold on
demo1 = 0.35:0.1:0.85;
demo2 = [0.01,0.03,0.06,0.09,0.12,0.15];%demo2 = 0.01:0.02:0.1;
set(gca,’yTick’,demo1)
set(gca,’xTick’,demo2)
%xlabel(‘delta/m’);ylabel(‘P_{l_{0}}’);
%axis([0.01,0.1,0.35,0.85]);hold on
%demo1 = 0.35:0.1:0.85;
%demo2 = 0.01:0.02:0.1;
%set(gca,’yTick’,demo1)
%set(gca,’xTick’,demo2)
% [X0,Y0] = meshgrid(lamda,det);
% figure,surf(X0,Y0,P)
% %figure,bar3(P)
% xlabel(‘lamda’);ylabel(‘det’);zlabel(‘P_{m_{0}}’);hold on
>> MHBew_beamindex_hengxiangxiangganchagndu
BLAS: trying environment BLAS_VERSION…
BLAS: loading C:MATLAB7binwin32atlas_Athlon.dll
BLAS: unloading libraries
错误使用 *
BLAS 加载错误:
C:MATLAB7binwin32atlas_Athlon.dll: 找不到指定的模块。
出错 integralCalc>iterateScalarValued (第 330 行)
x = NODES*halfh + midpt; % NNODES x nsubs
出错 integralCalc>vadapt (第 148 行)
[q,errbnd] = iterateScalarValued(u,tinterval,pathlen, …
出错 integralCalc (第 77 行)
[q,errbnd] = vadapt(vfunAB,interval, …
出错 integral (第 87 行)
Q = integralCalc(fun,a,b,opstruct);
出错 MHBew_beamindex_hengxiangxiangganchagndu (第 36 行)
qtemp=qtemp+integral(fun,0,R); integral MATLAB Answers — New Questions
my for loop stop after the first valid number has been found how do i fix this
I am new to Matlab, just learned the for loop, basically the loop run properly, but stop after the first valid number has found.
numbers=importdata(‘numbers.txt’);
result_1=[];
for i =1:numel(numbers);
num=numbers(i);
if mod(num, 10) == 6 && mod(num, 4) == 0
answer_1=[result_1,num];
end
end
fprintf(‘The numbers that ends in 6 and are divisible by 4: n’);
fprintf(‘%dn’,answer_1)I am new to Matlab, just learned the for loop, basically the loop run properly, but stop after the first valid number has found.
numbers=importdata(‘numbers.txt’);
result_1=[];
for i =1:numel(numbers);
num=numbers(i);
if mod(num, 10) == 6 && mod(num, 4) == 0
answer_1=[result_1,num];
end
end
fprintf(‘The numbers that ends in 6 and are divisible by 4: n’);
fprintf(‘%dn’,answer_1) I am new to Matlab, just learned the for loop, basically the loop run properly, but stop after the first valid number has found.
numbers=importdata(‘numbers.txt’);
result_1=[];
for i =1:numel(numbers);
num=numbers(i);
if mod(num, 10) == 6 && mod(num, 4) == 0
answer_1=[result_1,num];
end
end
fprintf(‘The numbers that ends in 6 and are divisible by 4: n’);
fprintf(‘%dn’,answer_1) help for loop not working properly MATLAB Answers — New Questions
How to plot Mach Number Contours
Greetings everyone, below is the code which generates the diverging portion of a supersonic nozzle using the Method Of Characteristics. How can I plot the Mach Number contours within the same plot along with a colorbar? Thank you!
%% Initialize datapoint matrices
clear
G=1.4;
Me = 2;
n = 55;
display = 1;
Km = zeros(n,n); % K- vlaues (Constant along right running characteristic lines)
Kp = zeros(n,n); % K+ vlaues (Constant along left running characteristic lines)
Theta = zeros(n,n); % Flow angles relative to the horizontal
Mu = zeros(n,n); % Mach angles
M = zeros(n,n); % Mach Numbers
x = zeros(n,n); % x-coordinates
y = zeros(n,n); % y-coordinates
%% Generate the contraction region using a 3rd order polynomial. Do not run this
%{
R = 287;
T0 = 300;
% Define the mach number in contraction region
uu = 25.0; %velocity in contraction region
a = sqrt(G*R*T0 – 0.5*(G-1)*uu^2); % local speed of sound
Mconv = uu/a; % Mach number
% Calculate the area ratio of contraction region
[~,~,~,~,area] = flowisentropic(G,Mconv); % area ratio
% Inlet convergent section geometry
y0 =1;
H_in = area * y0;
L_e = 1.5; %(1.0/3.0)*xwall(end);
%
[xconv,yconv] = Convergent_3rd(G,y0,H_in,L_e,n);
%}
%% Generate the convergent portion of a nozzle
% The inlet height/area and exit height/area(divergent) are same
% Therefore we have same A/A* = 1.6875
% Corresponding to Mach = 0.3722
%% Find NuMax (maximum expansion angle)
[~, NuMax, ~] = PMF(G,Me,0,0);
ThetaMax = NuMax/2;
%% Define some flow parameters of originating characteristic lines
dT = ThetaMax/n;
ThetaArc(:,1) = (0:dT:ThetaMax);
NuArc = ThetaArc;
KmArc = ThetaArc + NuArc;
[~, ~, MuArc(:,1)] = PMF(G,0,NuArc(:,1),0);
%% Coordinates of wall along curve from throat
y0 = 1; % Define throat half-height
ThroatCurveRadius = 1.5*y0; % Radius of curvature just downstream of the throat
% for larger factors, ywall deviates from A/A* preferred value is 1.1
%L_e = 1.1 * y0 * sind(ThetaMax);
[xarc, yarc] = Arc(ThroatCurveRadius,ThetaArc); % Finds x- and y-coordinates for given theta-values
yarc(:,1) = yarc(:,1) + y0; % Defines offset due to arc being above horizontal
%% Fill in missing datapoint info along first C+ line
% First centerline datapoint done manually
Km(:,1) = KmArc(2:length(KmArc),1);
Theta(:,1) = ThetaArc(2:length(KmArc),1);
Nu(:,1) = Theta(:,1);
Kp(:,1) = Theta(:,1)-Nu(:,1);
M(1,1) = 1.0;
Nu(1,1) = 0;
Mu(1,1) = 90;
y(1,1) = 0;
x(1,1) = xarc(2,1) + (y(1,1) – yarc(2,1))/tand((ThetaArc(2,1) – MuArc(2,1) – MuArc(2,1))/2);
% Finds the information at interior nodes along first C+ line
for i=2:n
[M(i,1), Nu(i,1), Mu(i,1)] = PMF(G,0,Nu(i,1),0);
s1 = tand((ThetaArc(i+1,1) – MuArc(i+1,1) + Theta(i,1) – Mu(i,1))/2);
s2 = tand((Theta(i-1,1) + Mu(i-1,1) + Theta(i,1) + Mu(i,1))/2);
x(i,1) = ((y(i-1,1)-x(i-1,1)*s2)-(yarc(i+1,1)-xarc(i+1,1)*s1))/(s1-s2);
y(i,1) = y(i-1,1) + (x(i,1)-x(i-1,1))*s2;
end
%% Find flow properties at remaining interior nodes
for j=2:n;
for i=1:n+1-j;
Km(i,j) = Km(i+1,j-1);
if i==1;
Theta(i,j) = 0;
Kp(i,j) = -Km(i,j);
Nu(i,j) = Km(i,j);
[M(i,j), Nu(i,j), Mu(i,j)] = PMF(G,0,Nu(i,j),0);
s1 = tand((Theta(i+1,j-1)-Mu(i+1,j-1)+Theta(i,j)-Mu(i,j))/2);
x(i,j) = x(i+1,j-1) – y(i+1,j-1)/s1;
y(i,j) = 0;
else
Kp(i,j) = Kp(i-1,j);
Theta(i,j) = (Km(i,j)+Kp(i,j))/2;
Nu(i,j) = (Km(i,j)-Kp(i,j))/2;
[M(i,j), Nu(i,j), Mu(i,j)] = PMF(G,0,Nu(i,j),0);
s1 = tand((Theta(i+1,j-1)-Mu(i+1,j-1)+Theta(i,j)-Mu(i,j))/2);
s2 = tand((Theta(i-1,j)+Mu(i-1,j)+Theta(i,j)+Mu(i,j))/2);
x(i,j) = ((y(i-1,j)-x(i-1,j)*s2)-(y(i+1,j-1)-x(i+1,j-1)*s1))/(s1-s2);
y(i,j) = y(i-1,j) + (x(i,j)-x(i-1,j))*s2;
end
end
end
%% Find wall node information
xwall = zeros(2*n,1);
ywall = xwall;
ThetaWall = ywall;
xwall(1:n,1) = xarc(2:length(xarc),1);
ywall(1:n,1) = yarc(2:length(xarc),1);
ThetaWall(1:n,1) = ThetaArc(2:length(xarc),1);
for i=1:n-1
ThetaWall(n+i,1) = ThetaWall(n-i,1);
end
for i=1:n
s1 = tand((ThetaWall(n+i-1,1) + ThetaWall(n+i,1))/2);
s2 = tand(Theta(n+1-i,i)+Mu(n+1-i,i));
xwall(n+i,1) = ((y(n+1-i,i)-x(n+1-i,i)*s2)-(ywall(n+i-1,1)-xwall(n+i-1,1)*s1))/(s1-s2);
ywall(n+i,1) = ywall(n+i-1,1) + (xwall(n+i,1)-xwall(n+i-1,1))*s1;
end
%% Provide wall geometry to user
assignin(‘caller’,’xwall’,xwall)
assignin(‘caller’,’ywall’,ywall)
assignin(‘caller’,’Coords’,[xwall ywall])
%% Generate the convergent portion of nozzle % do not run this
H_in = ywall(end);
L_e = xwall(end)*(1.0/3.0);
[xconv,yconv] = Convergent_new_3rd(y0,H_in,L_e,n);
%%
% Draw contour and characteristic web
if display == 1
plot(xwall,ywall,’-‘)
axis equal
axis([0 ceil(xwall(length(xwall),1)) 0 ceil(ywall(length(ywall),1))])
hold on
plot(xarc,yarc,’k-‘)
for i=1:n-1
plot(x(1:n+1-i,i),y(1:n+1-i,i))
end
for i=1:n
plot([xarc(i,1) x(i,1)],[yarc(i,1) y(i,1)])
plot([x(n+1-i,i) xwall(i+n,1)],[y(n+1-i,i) ywall(i+n,1)])
end
for c=1:n
for r=2:n+1-c
plot([x(c,r) x(c+1,r-1)],[y(c,r) y(c+1,r-1)])
end
end
xlabel(‘Length [x/y0]’)
ylabel(‘Height [y/y0]’)
endGreetings everyone, below is the code which generates the diverging portion of a supersonic nozzle using the Method Of Characteristics. How can I plot the Mach Number contours within the same plot along with a colorbar? Thank you!
%% Initialize datapoint matrices
clear
G=1.4;
Me = 2;
n = 55;
display = 1;
Km = zeros(n,n); % K- vlaues (Constant along right running characteristic lines)
Kp = zeros(n,n); % K+ vlaues (Constant along left running characteristic lines)
Theta = zeros(n,n); % Flow angles relative to the horizontal
Mu = zeros(n,n); % Mach angles
M = zeros(n,n); % Mach Numbers
x = zeros(n,n); % x-coordinates
y = zeros(n,n); % y-coordinates
%% Generate the contraction region using a 3rd order polynomial. Do not run this
%{
R = 287;
T0 = 300;
% Define the mach number in contraction region
uu = 25.0; %velocity in contraction region
a = sqrt(G*R*T0 – 0.5*(G-1)*uu^2); % local speed of sound
Mconv = uu/a; % Mach number
% Calculate the area ratio of contraction region
[~,~,~,~,area] = flowisentropic(G,Mconv); % area ratio
% Inlet convergent section geometry
y0 =1;
H_in = area * y0;
L_e = 1.5; %(1.0/3.0)*xwall(end);
%
[xconv,yconv] = Convergent_3rd(G,y0,H_in,L_e,n);
%}
%% Generate the convergent portion of a nozzle
% The inlet height/area and exit height/area(divergent) are same
% Therefore we have same A/A* = 1.6875
% Corresponding to Mach = 0.3722
%% Find NuMax (maximum expansion angle)
[~, NuMax, ~] = PMF(G,Me,0,0);
ThetaMax = NuMax/2;
%% Define some flow parameters of originating characteristic lines
dT = ThetaMax/n;
ThetaArc(:,1) = (0:dT:ThetaMax);
NuArc = ThetaArc;
KmArc = ThetaArc + NuArc;
[~, ~, MuArc(:,1)] = PMF(G,0,NuArc(:,1),0);
%% Coordinates of wall along curve from throat
y0 = 1; % Define throat half-height
ThroatCurveRadius = 1.5*y0; % Radius of curvature just downstream of the throat
% for larger factors, ywall deviates from A/A* preferred value is 1.1
%L_e = 1.1 * y0 * sind(ThetaMax);
[xarc, yarc] = Arc(ThroatCurveRadius,ThetaArc); % Finds x- and y-coordinates for given theta-values
yarc(:,1) = yarc(:,1) + y0; % Defines offset due to arc being above horizontal
%% Fill in missing datapoint info along first C+ line
% First centerline datapoint done manually
Km(:,1) = KmArc(2:length(KmArc),1);
Theta(:,1) = ThetaArc(2:length(KmArc),1);
Nu(:,1) = Theta(:,1);
Kp(:,1) = Theta(:,1)-Nu(:,1);
M(1,1) = 1.0;
Nu(1,1) = 0;
Mu(1,1) = 90;
y(1,1) = 0;
x(1,1) = xarc(2,1) + (y(1,1) – yarc(2,1))/tand((ThetaArc(2,1) – MuArc(2,1) – MuArc(2,1))/2);
% Finds the information at interior nodes along first C+ line
for i=2:n
[M(i,1), Nu(i,1), Mu(i,1)] = PMF(G,0,Nu(i,1),0);
s1 = tand((ThetaArc(i+1,1) – MuArc(i+1,1) + Theta(i,1) – Mu(i,1))/2);
s2 = tand((Theta(i-1,1) + Mu(i-1,1) + Theta(i,1) + Mu(i,1))/2);
x(i,1) = ((y(i-1,1)-x(i-1,1)*s2)-(yarc(i+1,1)-xarc(i+1,1)*s1))/(s1-s2);
y(i,1) = y(i-1,1) + (x(i,1)-x(i-1,1))*s2;
end
%% Find flow properties at remaining interior nodes
for j=2:n;
for i=1:n+1-j;
Km(i,j) = Km(i+1,j-1);
if i==1;
Theta(i,j) = 0;
Kp(i,j) = -Km(i,j);
Nu(i,j) = Km(i,j);
[M(i,j), Nu(i,j), Mu(i,j)] = PMF(G,0,Nu(i,j),0);
s1 = tand((Theta(i+1,j-1)-Mu(i+1,j-1)+Theta(i,j)-Mu(i,j))/2);
x(i,j) = x(i+1,j-1) – y(i+1,j-1)/s1;
y(i,j) = 0;
else
Kp(i,j) = Kp(i-1,j);
Theta(i,j) = (Km(i,j)+Kp(i,j))/2;
Nu(i,j) = (Km(i,j)-Kp(i,j))/2;
[M(i,j), Nu(i,j), Mu(i,j)] = PMF(G,0,Nu(i,j),0);
s1 = tand((Theta(i+1,j-1)-Mu(i+1,j-1)+Theta(i,j)-Mu(i,j))/2);
s2 = tand((Theta(i-1,j)+Mu(i-1,j)+Theta(i,j)+Mu(i,j))/2);
x(i,j) = ((y(i-1,j)-x(i-1,j)*s2)-(y(i+1,j-1)-x(i+1,j-1)*s1))/(s1-s2);
y(i,j) = y(i-1,j) + (x(i,j)-x(i-1,j))*s2;
end
end
end
%% Find wall node information
xwall = zeros(2*n,1);
ywall = xwall;
ThetaWall = ywall;
xwall(1:n,1) = xarc(2:length(xarc),1);
ywall(1:n,1) = yarc(2:length(xarc),1);
ThetaWall(1:n,1) = ThetaArc(2:length(xarc),1);
for i=1:n-1
ThetaWall(n+i,1) = ThetaWall(n-i,1);
end
for i=1:n
s1 = tand((ThetaWall(n+i-1,1) + ThetaWall(n+i,1))/2);
s2 = tand(Theta(n+1-i,i)+Mu(n+1-i,i));
xwall(n+i,1) = ((y(n+1-i,i)-x(n+1-i,i)*s2)-(ywall(n+i-1,1)-xwall(n+i-1,1)*s1))/(s1-s2);
ywall(n+i,1) = ywall(n+i-1,1) + (xwall(n+i,1)-xwall(n+i-1,1))*s1;
end
%% Provide wall geometry to user
assignin(‘caller’,’xwall’,xwall)
assignin(‘caller’,’ywall’,ywall)
assignin(‘caller’,’Coords’,[xwall ywall])
%% Generate the convergent portion of nozzle % do not run this
H_in = ywall(end);
L_e = xwall(end)*(1.0/3.0);
[xconv,yconv] = Convergent_new_3rd(y0,H_in,L_e,n);
%%
% Draw contour and characteristic web
if display == 1
plot(xwall,ywall,’-‘)
axis equal
axis([0 ceil(xwall(length(xwall),1)) 0 ceil(ywall(length(ywall),1))])
hold on
plot(xarc,yarc,’k-‘)
for i=1:n-1
plot(x(1:n+1-i,i),y(1:n+1-i,i))
end
for i=1:n
plot([xarc(i,1) x(i,1)],[yarc(i,1) y(i,1)])
plot([x(n+1-i,i) xwall(i+n,1)],[y(n+1-i,i) ywall(i+n,1)])
end
for c=1:n
for r=2:n+1-c
plot([x(c,r) x(c+1,r-1)],[y(c,r) y(c+1,r-1)])
end
end
xlabel(‘Length [x/y0]’)
ylabel(‘Height [y/y0]’)
end Greetings everyone, below is the code which generates the diverging portion of a supersonic nozzle using the Method Of Characteristics. How can I plot the Mach Number contours within the same plot along with a colorbar? Thank you!
%% Initialize datapoint matrices
clear
G=1.4;
Me = 2;
n = 55;
display = 1;
Km = zeros(n,n); % K- vlaues (Constant along right running characteristic lines)
Kp = zeros(n,n); % K+ vlaues (Constant along left running characteristic lines)
Theta = zeros(n,n); % Flow angles relative to the horizontal
Mu = zeros(n,n); % Mach angles
M = zeros(n,n); % Mach Numbers
x = zeros(n,n); % x-coordinates
y = zeros(n,n); % y-coordinates
%% Generate the contraction region using a 3rd order polynomial. Do not run this
%{
R = 287;
T0 = 300;
% Define the mach number in contraction region
uu = 25.0; %velocity in contraction region
a = sqrt(G*R*T0 – 0.5*(G-1)*uu^2); % local speed of sound
Mconv = uu/a; % Mach number
% Calculate the area ratio of contraction region
[~,~,~,~,area] = flowisentropic(G,Mconv); % area ratio
% Inlet convergent section geometry
y0 =1;
H_in = area * y0;
L_e = 1.5; %(1.0/3.0)*xwall(end);
%
[xconv,yconv] = Convergent_3rd(G,y0,H_in,L_e,n);
%}
%% Generate the convergent portion of a nozzle
% The inlet height/area and exit height/area(divergent) are same
% Therefore we have same A/A* = 1.6875
% Corresponding to Mach = 0.3722
%% Find NuMax (maximum expansion angle)
[~, NuMax, ~] = PMF(G,Me,0,0);
ThetaMax = NuMax/2;
%% Define some flow parameters of originating characteristic lines
dT = ThetaMax/n;
ThetaArc(:,1) = (0:dT:ThetaMax);
NuArc = ThetaArc;
KmArc = ThetaArc + NuArc;
[~, ~, MuArc(:,1)] = PMF(G,0,NuArc(:,1),0);
%% Coordinates of wall along curve from throat
y0 = 1; % Define throat half-height
ThroatCurveRadius = 1.5*y0; % Radius of curvature just downstream of the throat
% for larger factors, ywall deviates from A/A* preferred value is 1.1
%L_e = 1.1 * y0 * sind(ThetaMax);
[xarc, yarc] = Arc(ThroatCurveRadius,ThetaArc); % Finds x- and y-coordinates for given theta-values
yarc(:,1) = yarc(:,1) + y0; % Defines offset due to arc being above horizontal
%% Fill in missing datapoint info along first C+ line
% First centerline datapoint done manually
Km(:,1) = KmArc(2:length(KmArc),1);
Theta(:,1) = ThetaArc(2:length(KmArc),1);
Nu(:,1) = Theta(:,1);
Kp(:,1) = Theta(:,1)-Nu(:,1);
M(1,1) = 1.0;
Nu(1,1) = 0;
Mu(1,1) = 90;
y(1,1) = 0;
x(1,1) = xarc(2,1) + (y(1,1) – yarc(2,1))/tand((ThetaArc(2,1) – MuArc(2,1) – MuArc(2,1))/2);
% Finds the information at interior nodes along first C+ line
for i=2:n
[M(i,1), Nu(i,1), Mu(i,1)] = PMF(G,0,Nu(i,1),0);
s1 = tand((ThetaArc(i+1,1) – MuArc(i+1,1) + Theta(i,1) – Mu(i,1))/2);
s2 = tand((Theta(i-1,1) + Mu(i-1,1) + Theta(i,1) + Mu(i,1))/2);
x(i,1) = ((y(i-1,1)-x(i-1,1)*s2)-(yarc(i+1,1)-xarc(i+1,1)*s1))/(s1-s2);
y(i,1) = y(i-1,1) + (x(i,1)-x(i-1,1))*s2;
end
%% Find flow properties at remaining interior nodes
for j=2:n;
for i=1:n+1-j;
Km(i,j) = Km(i+1,j-1);
if i==1;
Theta(i,j) = 0;
Kp(i,j) = -Km(i,j);
Nu(i,j) = Km(i,j);
[M(i,j), Nu(i,j), Mu(i,j)] = PMF(G,0,Nu(i,j),0);
s1 = tand((Theta(i+1,j-1)-Mu(i+1,j-1)+Theta(i,j)-Mu(i,j))/2);
x(i,j) = x(i+1,j-1) – y(i+1,j-1)/s1;
y(i,j) = 0;
else
Kp(i,j) = Kp(i-1,j);
Theta(i,j) = (Km(i,j)+Kp(i,j))/2;
Nu(i,j) = (Km(i,j)-Kp(i,j))/2;
[M(i,j), Nu(i,j), Mu(i,j)] = PMF(G,0,Nu(i,j),0);
s1 = tand((Theta(i+1,j-1)-Mu(i+1,j-1)+Theta(i,j)-Mu(i,j))/2);
s2 = tand((Theta(i-1,j)+Mu(i-1,j)+Theta(i,j)+Mu(i,j))/2);
x(i,j) = ((y(i-1,j)-x(i-1,j)*s2)-(y(i+1,j-1)-x(i+1,j-1)*s1))/(s1-s2);
y(i,j) = y(i-1,j) + (x(i,j)-x(i-1,j))*s2;
end
end
end
%% Find wall node information
xwall = zeros(2*n,1);
ywall = xwall;
ThetaWall = ywall;
xwall(1:n,1) = xarc(2:length(xarc),1);
ywall(1:n,1) = yarc(2:length(xarc),1);
ThetaWall(1:n,1) = ThetaArc(2:length(xarc),1);
for i=1:n-1
ThetaWall(n+i,1) = ThetaWall(n-i,1);
end
for i=1:n
s1 = tand((ThetaWall(n+i-1,1) + ThetaWall(n+i,1))/2);
s2 = tand(Theta(n+1-i,i)+Mu(n+1-i,i));
xwall(n+i,1) = ((y(n+1-i,i)-x(n+1-i,i)*s2)-(ywall(n+i-1,1)-xwall(n+i-1,1)*s1))/(s1-s2);
ywall(n+i,1) = ywall(n+i-1,1) + (xwall(n+i,1)-xwall(n+i-1,1))*s1;
end
%% Provide wall geometry to user
assignin(‘caller’,’xwall’,xwall)
assignin(‘caller’,’ywall’,ywall)
assignin(‘caller’,’Coords’,[xwall ywall])
%% Generate the convergent portion of nozzle % do not run this
H_in = ywall(end);
L_e = xwall(end)*(1.0/3.0);
[xconv,yconv] = Convergent_new_3rd(y0,H_in,L_e,n);
%%
% Draw contour and characteristic web
if display == 1
plot(xwall,ywall,’-‘)
axis equal
axis([0 ceil(xwall(length(xwall),1)) 0 ceil(ywall(length(ywall),1))])
hold on
plot(xarc,yarc,’k-‘)
for i=1:n-1
plot(x(1:n+1-i,i),y(1:n+1-i,i))
end
for i=1:n
plot([xarc(i,1) x(i,1)],[yarc(i,1) y(i,1)])
plot([x(n+1-i,i) xwall(i+n,1)],[y(n+1-i,i) ywall(i+n,1)])
end
for c=1:n
for r=2:n+1-c
plot([x(c,r) x(c+1,r-1)],[y(c,r) y(c+1,r-1)])
end
end
xlabel(‘Length [x/y0]’)
ylabel(‘Height [y/y0]’)
end #contour plot, nozzle, mach number MATLAB Answers — New Questions