How to convert class cell to vector?

조회 수: 3 (최근 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

카테고리

Help CenterFile Exchange에서 Continuous Wavelet Transforms에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by