How to convert class cell to vector?

4 次查看(过去 30 天)
A Lumbini
A Lumbini 2024-6-3
编辑: Arun 2024-6-11
wavelet = 'db4';
level = 6;
tt=0:(0.25*10^(-3)):(0.25*10^(-3))*ceil(N);
Unrecognized function or variable '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 个评论
Rik
Rik 2024-6-3
I can't run your code and the question in the title doesn't match the message in the screenshot.
A Lumbini
A Lumbini 2024-6-3
编辑:A Lumbini 2024-6-3
@Rik Sorry sir
I have provided only part of my program
The Currentwindow's and Voltagewindow's i have mentioned are the signals taken from Simulink model and 'N' is the length of the Currentwindow. This code is written in matlab function block
and my question is that when i use defcoef() function then i am getting error that dot() function cannot be applied to class 'cell' values. So, i have used cell2mat() function to convert class 'cell' to vector which is further giving error as
Then i used str2double() function and got the same error
So thus i gave the title as how to convert cell to vector because thought it is the main problem

请先登录,再进行评论。

回答(1 个)

Arun
Arun 2024-6-11
编辑:Arun 2024-6-11
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:
  1. 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.
  2. 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.
  3. 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.
  4. 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:
2. MATLAB documentation for “coder.extrinsic” function: https://www.mathworks.com/help/simulink/slref/coder.extrinsic.html
I hope this helps!
Best regards
Arun

产品


版本

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by