How to convert class cell to vector?
3 views (last 30 days)
Show older comments
wavelet = 'db4';
level = 6;
tt=0:(0.25*10^(-3)):(0.25*10^(-3))*ceil(N);
ref=cos(2*pi*50*tt);
[CR, LR] = wavedec(CurrentwindowR, level, wavelet);
[CY, LY] = wavedec(CurrentwindowY, level, wavelet);
[CB, LB] = wavedec(CurrentwindowB, level, wavelet);
[CRvolt, LRvolt] = wavedec(VoltagewindowR, level, wavelet);
[CYvolt, LYvolt] = wavedec(VoltagewindowY, level, wavelet);
[CBvolt, LBvolt] = wavedec(VoltagewindowB, level, wavelet);
[Cref, Lref] = wavedec(ref, level, wavelet);
coder.extrinsic('str2double')
AppR=str2double(detcoef(CR,LR,level));
AppY=str2double(detcoef(CY,LY,level));
AppB=str2double(detcoef(CB,LB,level));
AppvoltR=str2double(detcoef(CRvolt,LRvolt,level));
AppvoltY=str2double(detcoef(CYvolt,LYvolt,level));
AppvoltB=str2double(detcoef(CBvolt,LBvolt,level));
Appref=str2double(detcoef(Cref,Lref,level));
thetaR= acosd((dot(Appref,AppR))/(norm(Appref)*norm(AppR)));
thetaY= acosd((dot(Appref,AppY))/(norm(Appref)*norm(AppY)));
thetaB= acosd((dot(Appref,AppB))/(norm(Appref)*norm(AppB)));
refR=cos(2*pi*50*tt+thetaR*pi/180);
refY=cos(2*pi*50*tt+thetaY*pi/180);
refB=cos(2*pi*50*tt+thetaB*pi/180);
2 Comments
Rik
on 3 Jun 2024
I can't run your code and the question in the title doesn't match the message in the screenshot.
Answers (1)
Arun
on 11 Jun 2024
Edited: Arun
on 11 Jun 2024
I understand that you get the specified error message for using the code in “MATLAB function block” inside the Simulink model.
This error typically occurs in the context of using MATLAB's “Code Generation” features or within Simulink models, especially when dealing with “MATLAB Function blocks” or writing code intended for code generation. It is often related to the use of certain MATLAB constructs or functions that are not supported for code generation or are restricted in how they can be used.
The error message means that “mxArrays”, cannot be indexed, which are objects returned from extrinsic function calls. Following are some ways to handle the error:
- Preallocate Arrays and Structures: Ensure all arrays, cell arrays, and structures are preallocated with a fixed size before entering code generation sections. For variable-size data, use bounded sizes known at compile time.
- Avoid Unsupported Functions: Check the MATLAB documentation to ensure that all functions used are supported for code generation. Replace unsupported functions with equivalent supported ones if necessary.
- Use `coder.extrinsic` for Unsupported Functions: If need to use a function that is not supported for code generation, declare it as extrinsic using `coder.extrinsic('functionName')`. This tells the code generator that the function will only be executed in MATLAB and not in the generated code. However, this is typically only a workaround for simulation and not a solution for generating deployable code.
- Explicitly Define Variable types and size: Use functions like `zeros`, `ones`, or `coder.typeof` to explicitly define the types and sizes of variables. This is especially important for structures and arrays that might otherwise be considered dynamic.
Here are some links that might be useful:
1. Functions and objects supported for code generation: https://www.mathworks.com/help/coder/ug/functions-and-objects-supported-for-cc-code-generation.html
2. MATLAB documentation for “coder.extrinsic” function: https://www.mathworks.com/help/simulink/slref/coder.extrinsic.html
I hope this helps!
Best regards
Arun
0 Comments
See Also
Categories
Find more on Continuous Wavelet Transforms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!