How to read just the powers from matlab output
Afficher commentaires plus anciens
How to read/print the powers from the matlab output function coeffs ?
l^4*w^3*z^1 and l^4*w^3
I would like to obtain numbers 341 and 340 from the above sequence.
[r, t] = coeffs(10*z^2*w^4 + 5*w^2*l^2 + 2*z^6)
t =
[ l^2*w^2, w^4*z^2, z^6]
% 220 402 006
Réponse acceptée
Plus de réponses (1)
Image Analyst
le 18 Juin 2020
Here's one way, using isstrprop():
chr = 'l^4*w^3*z^1 and 8^4*w^3' % Create test character array.
mask = isstrprop(chr,'digit') % Get locations of numbers
caretLocations = chr == '^'
caretLocations = [false, caretLocations(1:end-1)] % Shift to the right.
mask = mask & caretLocations
chr(~mask) = ' '
numbers = sscanf(chr, ' %f')
1 commentaire
Image Analyst
le 19 Juin 2020
Results:
numbers =
4
3
1
4
3
Catégories
En savoir plus sur MATLAB dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!