Re: [Scilab-users] Loop over string vector

2023-10-04 Thread Stéphane Mottelet

Hello,

Here is a one liner solution:

HEX=[
"FF"
"D9"
"CC80FF"
"C2FF00"
"FFB5B5"
"909090"
"3050F8"
"FF0D0D"
"90E050"
"B3E3F5"
]

--> matrix(hex2dec(strsplit(strcat(HEX),2:2:length(strcat(HEX))-1)),3,-1)'
ans  =

  255.   255.   255.
  217.   255.   255.
  204.   128.   255.
  194.   255.   0.
  255.   181.   181.
  144.   144.   144.
  48.80.248.
  255.   13.13.
  144.   224.   80.
  179.   227.   245.


S.

On 02/10/2023 09:52, Lester Anderson wrote:
Hello,

I am trying to loop through a vector of strings but having issues with the 
strsplit function.

The vector consists of HEX values for colours. I created a simple function to 
get RGB values.

function rgb=hex2rgb(x)
   // x=string input
   hexrgb=strsplit(x,[2 4])';
   rgb=hex2dec(hexrgb);
endfunction

--> HEX
HEX  =

 "FF"
 "D9"
 "CC80FF"
 "C2FF00"
 "FFB5B5"
 "909090"
 "3050F8"
 "FF0D0D"
 "90E050"
 "B3E3F5"
etc

The function works fine with single values as that is what strsplit expects, 
but not sure how to make it run through the string vector; indexing causes 
issues. Any pointers would be helpful.

Thanks
Lester

This email and any attachments are intended solely for the use of the 
individual or entity to whom it is addressed and may be confidential and/or 
privileged.

If you are not one of the named recipients or have received this email in error,

(i) you should not read, disclose, or copy it,

(ii) please notify sender of your receipt by reply email and delete this email 
and all attachments,

(iii) Dassault Systèmes does not accept or assume any liability or 
responsibility for any use of or reliance on this email.


Please be informed that your personal data are processed according to our data 
privacy policy as described on our website. Should you have any questions 
related to personal data protection, please contact 3DS Data Protection Officer 
https://www.3ds.com/privacy-policy/contact/




___
users mailing list - users@lists.scilab.org
Click here to unsubscribe: 

https://lists.scilab.org/mailman/listinfo/users


This email and any attachments are intended solely for the use of the 
individual or entity to whom it is addressed and may be confidential and/or 
privileged.

If you are not one of the named recipients or have received this email in error,

(i) you should not read, disclose, or copy it,

(ii) please notify sender of your receipt by reply email and delete this email 
and all attachments,

(iii) Dassault Systèmes does not accept or assume any liability or 
responsibility for any use of or reliance on this email.


Please be informed that your personal data are processed according to our data 
privacy policy as described on our website. Should you have any questions 
related to personal data protection, please contact 3DS Data Protection Officer 
https://www.3ds.com/privacy-policy/contact/

___
users mailing list - users@lists.scilab.org
Click here to unsubscribe: 
https://lists.scilab.org/mailman/listinfo/users


Re: [Scilab-users] Loop over string vector

2023-10-03 Thread Lester Anderson
Hello

Thanks for the suggestions. The 'part' option worked but the function fails at 
hexrgb=strsplit(x(i),[2 4])';
strsplit: Wrong size for input argument #1: A single string expected.

This was the issue I was having initially, logically it should work, but looks 
like it just sees x as a whole.

Lester

On Tue, 3 Oct 2023 at 08:03, Steer Serge 
mailto:serge.st...@laposte.net>> wrote:
With a for loop

function rgb=hex2rgb(x)
// x=string input
   rgb=[];
   for i=1:size(x,"*")
   hexrgb=strsplit(x(i),[2 4])';
rgb=[rgb;hex2dec(hexrgb)];
  end
endfunction


You can also use the part function which works with vectors
rgb=[part(x,1:2),part(x,3:4),part(x,5:6)];

Le 02/10/2023 à 09:52, Lester Anderson a écrit :
Hello,

I am trying to loop through a vector of strings but having issues with the 
strsplit function.

The vector consists of HEX values for colours. I created a simple function to 
get RGB values.

function rgb=hex2rgb(x)
// x=string input
hexrgb=strsplit(x,[2 4])';
rgb=hex2dec(hexrgb);
endfunction

--> HEX
 HEX  =

  "FF"
  "D9"
  "CC80FF"
  "C2FF00"
  "FFB5B5"
  "909090"
  "3050F8"
  "FF0D0D"
  "90E050"
  "B3E3F5"
etc

The function works fine with single values as that is what strsplit expects, 
but not sure how to make it run through the string vector; indexing causes 
issues. Any pointers would be helpful.

Thanks
Lester

This email and any attachments are intended solely for the use of the 
individual or entity to whom it is addressed and may be confidential and/or 
privileged.

If you are not one of the named recipients or have received this email in error,

(i) you should not read, disclose, or copy it,

(ii) please notify sender of your receipt by reply email and delete this email 
and all attachments,

(iii) Dassault Systèmes does not accept or assume any liability or 
responsibility for any use of or reliance on this email.


Please be informed that your personal data are processed according to our data 
privacy policy as described on our website. Should you have any questions 
related to personal data protection, please contact 3DS Data Protection Officer 
https://www.3ds.com/privacy-policy/contact/




___
users mailing list - users@lists.scilab.org
Click here to unsubscribe: 

https://lists.scilab.org/mailman/listinfo/users



This email and any attachments are intended solely for the use of the 
individual or entity to whom it is addressed and may be confidential and/or 
privileged.

If you are not one of the named recipients or have received this email in error,

(i) you should not read, disclose, or copy it,

(ii) please notify sender of your receipt by reply email and delete this email 
and all attachments,

(iii) Dassault Systèmes does not accept or assume any liability or 
responsibility for any use of or reliance on this email.


Please be informed that your personal data are processed according to our data 
privacy policy as described on our website. Should you have any questions 
related to personal data protection, please contact 3DS Data Protection Officer 
https://www.3ds.com/privacy-policy/contact/

___
users mailing list - users@lists.scilab.org
Click here to unsubscribe: 
https://lists.scilab.org/mailman/listinfo/users


Re: [Scilab-users] Loop over string vector

2023-10-03 Thread Lester Anderson
Quick update. Following Serge, I managed to get from the HEX code to RGB via 
the following, avoiding the issue of the submatrix incorrectly defined.


rgb=[part(Hex_colour,1:2),part(Hex_colour,3:4),part(Hex_colour,5:6)];

for i = 1:size(rgb,1)
red(i)=hex2dec(rgb(i,1));
green(i)=hex2dec(rgb(i,2));
blue(i)=hex2dec(rgb(i,3));
RGB_colours=cat(2,red,green,blue);
end

On Tue, 3 Oct 2023 at 12:42, Lester Anderson 
mailto:arctica1...@gmail.com>> wrote:
Hello

Thanks for the suggestions. The 'part' option worked but the function fails at 
hexrgb=strsplit(x(i),[2 4])';
strsplit: Wrong size for input argument #1: A single string expected.

This was the issue I was having initially, logically it should work, but looks 
like it just sees x as a whole.

Lester

On Tue, 3 Oct 2023 at 08:03, Steer Serge 
mailto:serge.st...@laposte.net>> wrote:
With a for loop

function rgb=hex2rgb(x)
// x=string input
   rgb=[];
   for i=1:size(x,"*")
   hexrgb=strsplit(x(i),[2 4])';
rgb=[rgb;hex2dec(hexrgb)];
  end
endfunction


You can also use the part function which works with vectors
rgb=[part(x,1:2),part(x,3:4),part(x,5:6)];

Le 02/10/2023 à 09:52, Lester Anderson a écrit :
Hello,

I am trying to loop through a vector of strings but having issues with the 
strsplit function.

The vector consists of HEX values for colours. I created a simple function to 
get RGB values.

function rgb=hex2rgb(x)
// x=string input
hexrgb=strsplit(x,[2 4])';
rgb=hex2dec(hexrgb);
endfunction

--> HEX
 HEX  =

  "FF"
  "D9"
  "CC80FF"
  "C2FF00"
  "FFB5B5"
  "909090"
  "3050F8"
  "FF0D0D"
  "90E050"
  "B3E3F5"
etc

The function works fine with single values as that is what strsplit expects, 
but not sure how to make it run through the string vector; indexing causes 
issues. Any pointers would be helpful.

Thanks
Lester

This email and any attachments are intended solely for the use of the 
individual or entity to whom it is addressed and may be confidential and/or 
privileged.

If you are not one of the named recipients or have received this email in error,

(i) you should not read, disclose, or copy it,

(ii) please notify sender of your receipt by reply email and delete this email 
and all attachments,

(iii) Dassault Systèmes does not accept or assume any liability or 
responsibility for any use of or reliance on this email.


Please be informed that your personal data are processed according to our data 
privacy policy as described on our website. Should you have any questions 
related to personal data protection, please contact 3DS Data Protection Officer 
https://www.3ds.com/privacy-policy/contact/




___
users mailing list - users@lists.scilab.org
Click here to unsubscribe: 

https://lists.scilab.org/mailman/listinfo/users



This email and any attachments are intended solely for the use of the 
individual or entity to whom it is addressed and may be confidential and/or 
privileged.

If you are not one of the named recipients or have received this email in error,

(i) you should not read, disclose, or copy it,

(ii) please notify sender of your receipt by reply email and delete this email 
and all attachments,

(iii) Dassault Systèmes does not accept or assume any liability or 
responsibility for any use of or reliance on this email.


Please be informed that your personal data are processed according to our data 
privacy policy as described on our website. Should you have any questions 
related to personal data protection, please contact 3DS Data Protection Officer 
https://www.3ds.com/privacy-policy/contact/

___
users mailing list - users@lists.scilab.org
Click here to unsubscribe: 
https://lists.scilab.org/mailman/listinfo/users


Re: [Scilab-users] Loop over string vector

2023-10-03 Thread Pinede Romain
Hello,

A basic solution would be to use part (several times) instead of strsplit:

function rgb=hex2rgb2(x)
// Assuming HEX is a column vector
hexrgb = [part(HEX, 1:2), part(HEX, 3:4), part(HEX, 5:6)];
rgb = hex2dec(hexrgb);
endfunction

Romain

De : users  De la part de Lester Anderson
Envoyé : lundi 2 octobre 2023 09:53
À : International users mailing list for Scilab. 
Objet : [Scilab-users] Loop over string vector

Hello,

I am trying to loop through a vector of strings but having issues with the 
strsplit function.

The vector consists of HEX values for colours. I created a simple function to 
get RGB values.

function rgb=hex2rgb(x)

// x=string input

hexrgb=strsplit(x,[2 4])';

rgb=hex2dec(hexrgb);

endfunction
--> HEX
 HEX  =

  "FF"
  "D9"
  "CC80FF"
  "C2FF00"
  "FFB5B5"
  "909090"
  "3050F8"
  "FF0D0D"
  "90E050"
  "B3E3F5"
etc

The function works fine with single values as that is what strsplit expects, 
but not sure how to make it run through the string vector; indexing causes 
issues. Any pointers would be helpful.

Thanks
Lester

This email and any attachments are intended solely for the use of the 
individual or entity to whom it is addressed and may be confidential and/or 
privileged.

If you are not one of the named recipients or have received this email in error,

(i) you should not read, disclose, or copy it,

(ii) please notify sender of your receipt by reply email and delete this email 
and all attachments,

(iii) Dassault Systèmes does not accept or assume any liability or 
responsibility for any use of or reliance on this email.


Please be informed that your personal data are processed according to our data 
privacy policy as described on our website. Should you have any questions 
related to personal data protection, please contact 3DS Data Protection Officer 
https://www.3ds.com/privacy-policy/contact/



This email and any attachments are intended solely for the use of the 
individual or entity to whom it is addressed and may be confidential and/or 
privileged.

If you are not one of the named recipients or have received this email in error,

(i) you should not read, disclose, or copy it,

(ii) please notify sender of your receipt by reply email and delete this email 
and all attachments,

(iii) Dassault Systèmes does not accept or assume any liability or 
responsibility for any use of or reliance on this email.


Please be informed that your personal data are processed according to our data 
privacy policy as described on our website. Should you have any questions 
related to personal data protection, please contact 3DS Data Protection Officer 
https://www.3ds.com/privacy-policy/contact/

___
users mailing list - users@lists.scilab.org
Click here to unsubscribe: 
https://lists.scilab.org/mailman/listinfo/users